Basically, you roll over a piece of text, and it follows the mouse, using the
following code.
onClipEvent (load) {
_x = this._x;
_y = this._y;
speed = 44;
}
onClipEvent (enterFrame) {
if (_global.penthouseshit == 1) {
endX = _root._xmouse;
endY = _root._ymouse;
_x += (endX-_x)/speed;
_y += (endY-_y)/speed;
}
}
However, the problem is that when I roll off this thing, it is sort of
snapping back to it's original position. I'm thinking there is a way to animate
it back to it's original state, but I'm not sure how to do this.
Could you show me the way?
Thanks.
kglad - 28 Dec 2006 01:20 GMT
change the first two lines of that onLoad statement to store your movieclip's
initial _x and _y properties. (the first two lines currently do nothing.)
and use an else branch of your if-statement to update that movieclip's _x,_y
properties using those initial properties instead of endX and endY.
dtrace - 28 Dec 2006 03:18 GMT
That makes sense and works...but the issue is now this other tween that you
helped me with, that makes the MC hover.
This is the code that makes them hover.
I think it's the code that tells this hovering tween to 'start tween' that is
causing the MC to jump.
Here is the fla so you know what I'm talking about.
http://www.devontracey.com/current3.fla
thanks.
import mx.transitions.Tween;
function startTween(mc:MovieClip, range_num:Number, seconds:Number):Void {
if (!mc.xMin) {
mc.xMin = mc._x-range_num;
mc.xMax = mc._x+range_num-7;
mc.yMin = mc._y-range_num;
mc.yMax = mc._y+range_num-14;
}
//adjust the easing class as needed
mc.xNew = (Math.random()*(mc.xMax-mc.xMin))+mc.xMin;
mc.yNew = (Math.random()*(mc.yMax-mc.yMin))+mc.yMin;
mc.xTween = new Tween(mc, "_x", Regular.easeInOut, mc._x, mc.xNew, seconds,
false);
mc.yTween = new Tween(mc, "_y", Regular.easeInOut, mc._y, mc.yNew, seconds,
false);
mc.xTweenFinished = 0;
mc.yTweenFinished = 0;
mc.xTween.onMotionFinished = function() {
mc.xTweenFinished = 1;
if (mc.xTweenFinished & mc.yTweenFinished) {
startTween(mc, range_num, seconds);
}
};
mc.yTween.onMotionFinished = function() {
mc.yTweenFinished = 1;
if (mc.xTweenFinished & mc.yTweenFinished) {
startTween(mc, range_num, seconds);
}
};
}
startTween(penthouse, 12, 72);
startTween(midnight, 12, 82);
startTween(photo, 12, 62);
startTween(meeting, 12, 66);
startTween(everything, 12, 80);
startTween(space, 12, 77);
penthousebutton.onRollOver = function() {
penthouse.xTween.stop();
penthouse.yTween.stop();
};
midnightbutton.onRollOver = function() {
midnight.xTween.stop();
midnight.yTween.stop();
};
midnightbutton.onRollOut = function() {
midnight.xTween.resume();
midnight.yTween.resume();
};
photobutton.onRollOver = function() {
photo.xTween.stop();
photo.yTween.stop();
};
photobutton.onRollOut = function() {
photo.xTween.resume();
photo.yTween.resume();
};
meetingbutton.onRollOver = function() {
meeting.xTween.stop();
meeting.yTween.stop();
};
meetingbutton.onRollOut = function() {
meeting.xTween.resume();
meeting.yTween.resume();
};
everythingbutton.onRollOver = function() {
everything.xTween.stop();
everything.yTween.stop();
};
everythingbutton.onRollOut = function() {
everything.xTween.resume();
everything.yTween.resume();
};
yourbutton.onRollOver = function() {
space.xTween.stop();
space.yTween.stop();
};
yourbutton.onRollOut = function() {
space.xTween.resume();
space.yTween.resume();
};
kglad - 28 Dec 2006 05:18 GMT
you many not want to resume those tweens onRollOut then. if you want to start
a new tween onRollOut (using the possibly new _x and _y properties of your
buttons), then change the current rollOut handlers to do just that.
dtrace - 29 Dec 2006 20:16 GMT
kglad,
That seems to make sense, to start a new tween on roll out based on the
current x and y position of the mc. That way, it wouldn't 'jump' but would
instead go smoothly into the hovering.
But, how would I start a new tween on roll out? The code would have to be the
same as the previous 'hovering' function you made, right? But I would have to
give it a new name?
Then, if you roll over the mc again, wouldn't it only stop the first Tween
instance?
How would I make it stop the second one?
Thanks
kglad - 30 Dec 2006 02:12 GMT
you'll delete the first tween onRollOut (or onRollOver) and start a new one.
for example:
startTween(midnight, 12, 5);
midnight.onRollOver = function() {
delete midnight.xTween;
delete midnight.yTween;
};
midnight.onRollOut = function() {
startTween(midnight, 12, 5);
};
dtrace - 30 Dec 2006 09:44 GMT
kglad, amazing, it works. Thanks so much, you are a stud.
Do you have a personal site? I have tons of flash work and would like to know what you're up to, to perhaps call upon from time to time.
kglad - 30 Dec 2006 17:44 GMT
www.gladstien.com
i'm a mathematician who changed careers to medicine. my day-job is pediatrics
but i do a fair amount of med-expert work and lately, flash programming for a
few clients that found me on this forum.