I've been trying to get this to work for a while. I have 25 frames I want to loop, but on a mouseover I want it to jump to frame 26 and continue. Any suggestions?
Actionscript 2 or 3 is fine...
I've been trying to get this to work for a while. I have 25 frames I want to loop, but on a mouseover I want it to jump to frame 26 and continue. Any suggestions?
Actionscript 2 or 3 is fine...
If you want to avoid using the timeline at all, you can either check currentFrame on each frame using an ENTER_FRAME handler, or you can use the addFrameScript() method:
var isIdle : Boolean = true;
var loopIfIdle: Function = function() : void
{
if (isIdle)
mc.gotoAndPlay(1);
};
mc.addFrameScript(24, loopIfIdle);
mc.addEventListener(MouseEvent.MOUSE_OVER, handleMouseOver);
// The mouse handler:
function handleMouseOver(ev : MouseEvent) : void
{
isIdle = false;
}
Essentially, what happens here is that a boolean variable is declared, which will be used to indicate whether the Flash stage has been interacted with (hovered) yet. Using a closure (a method that inherits variables in it's surrounding scope) we create the loopIfIdle function which will have access to this flag.
The addFrameScript() does more or less exactly the same thing as adding code on a frame in the Flash CS3/CS4 timeline. As such, the loopIfIdle function will be executed each time the playhead passes frame 25. But now, because we are using a closure, we can check the state of the isIdle flag from within the frame script.
The MOUSE_OVER event handler will set isIdle to false, to indicate that the stage has been hovered. This means that the next time that loopIfIdle is invoked, it will not loop (i.e. move back to frame 1) hence achieving the effect that you're after.
An even simpler solution would be to simply gotoAndPlay(26) in the MOUSE_OVER handler, and ignore the entire frame script and isIdle flag approach. This will not, however, guarantee a smooth transition from loop to frame 26 (imagine if the mouse enters the stage on frame 1, which will then jump straight to 26.) Depending on your requirements, this might still be a good alternative.