PDA

View Full Version : pausing an animation on rollover


newttyy
08-13-2007, 04:10 PM
Hello there.

Lets say I have a circle movie clip moving up and down on the scene (circle_mc) - no animation is done on the timline. The ball is beeing moved by actionscript.

And next to it I have a button (button_mc) that if you rollover it, will stop the circle and if you rollout will make the circle play again from the point where it was.

How I would write the code (I did search a similar post but I was unable to find one)?

Please help!!!!!

Noct
08-13-2007, 06:28 PM
Well, it would matter how you were animating the circle_mc really...
If you were doing it via the Tween class, it would go something like this:
import mx.transitions.Tween;
import mx.transitions.easing.*;
var circleTween:Object = new Tween(this.circle_mc, "_y", Strong.easeInOut, 0, 100, 2, true);
circleTween.onMotionFinished = function() {
circleTween.yoyo();
};
button_mc.onRollOver = function() {
circleTween.stop();
};
button_mc.onRollOut = function() {
circleTween.resume();
};

newttyy
08-14-2007, 07:19 PM
Thanks Noct!

I'm not using tweens. I'm trying to expand my understanding of actionscript and i was trying to actually code it without any kind of tween class.

Do you know how to do it without?

I belive I will have to use an if ... else statment somwhere in the code?

kool-Aid
08-14-2007, 07:53 PM
I just addressed a little animating with AS through fuse in this thread. Might help ya a little.

http://www.actionscript.org/forums/showthread.php3?t=144642

Noct
08-14-2007, 08:05 PM
Well...I'm in love with the tween class these days, but sure, you could do it without it...

You could do it pretty easily with an onEnterFrame that checks a variable and only moves the object when that variable is set correctly. Then you could just toggle that variable with the rollOver of the button...
But...that is going to be much harder on the processor that way..

I would suggest creating a function that moves the object, and calling/deleting that function when the rollOver/Out occurs.
Maybe something like:
function startCircle() {
this.circle_mc.onEnterFrame = function() {
this._y++;
};
}
function stopCircle() {
delete this.circle_mc.onEnterFrame;
}
button_mc.onRollOver = function() {
stopCircle();
};
button_mc.onRollOut = function() {
startCircle();
};

@kool-Aid
Heh, if he doesn't want to use the tween class because he thinks it's less of an AS education, I doubt he's going to want to use fuse man...

newttyy
08-15-2007, 02:16 AM
Hello again guys,


Noct, you were right on the spot! That was exactly what I need it. I personally am in love with tween class as well; mostly use the "mc_tween" class - http://hosted.zeh.com.br/mctween/documentation.html.
The only thing is that I realize is making me lazy :), and don't get to learn more about the actual actionscript.


kool-Aid, thanks for your help as well. It did learned me a little bit as well, but for my sample it confused me a little bit :) - never used fuse before.
I had an "if..else" condition, but for whatever reason it was passing only trough the "if..." and completely ignoring the "else".
I realized after, that the problem was because was not getting the new coordinates and "else" was never getting its condition. I just didn't know how to check for the new coordinates.

With a little function in front (as Noct just showed me), my problem was solved.

THANKS!!!! ;)

kool-Aid
08-15-2007, 03:19 PM
ya i know the code was a little sloppy, i did it in a couple seconds to answer someones question so i copy pasted some code etc. I posted the example for you just because you seemed interested in animating through action script and fuse is a really cool and time saving tool. I know it is a lot like the tween class. Just thought you might be interested. I will go back into the thread and clean up my code for future viewers.

good luck man.

newttyy
08-15-2007, 03:38 PM
I have to admit fuse is looking pretty interesting ... I might actually get in to it :).

Thanks again and good luck as well!