Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Stopping reverse animation where I want it to stop.

Explorer ,
Oct 01, 2014 Oct 01, 2014

I have some code that reverses the animation on the timeline when an object is rolled over.  I want to add a mouse out event that will then stop that animation dead at the frame it's sitting on when the mouse rolls off of it.  So if the animation is 100 frames long and you rollover this object it'll start playing reverse but if I roll off the object when the animation is at frame 50 it'll stop at frame 50 and won't start up again unless I roll over that object.  I've done something similar to this with a different reverse code but I'd like to try and make it work with this code because it's a much less convoluted chunk of code.  I thought simply putting stop(); as the mouse out function would work since it's referencing local animation but it doesn't.  The animation will not stop until it gets to frame one.  Here's the code I have, can I modify this to do what I want?

right.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandler);

function fl_MouseOverHandler(event:MouseEvent):void

{

    play()

}

right.addEventListener(MouseEvent.MOUSE_OUT, fl_MouseOutHandler);

function fl_MouseOutHandler(event:MouseEvent):void

{

    stop()

}

left.addEventListener(MouseEvent.MOUSE_OVER, fl_MouseOverHandler_2);

function fl_MouseOverHandler_2(event:MouseEvent):void

{

    var targetFrame:int = 1;

// if we are ahead of the target, start going backwards

if(currentFrame > targetFrame) stage.addEventListener(Event.ENTER_FRAME,goBack);

function goBack(evt:Event):void

{

    prevFrame();

    // kill the event listener when the target is reached

    if(currentFrame <= targetFrame) stage.removeEventListener(Event.ENTER_FRAME,goBack);

}

}

left.addEventListener(MouseEvent.MOUSE_OUT, fl_MouseOutHandler_2);

function fl_MouseOutHandler_2(event:MouseEvent):void

{

    stop()

   

}

TOPICS
ActionScript
360
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Oct 02, 2014 Oct 02, 2014
LATEST

You should never nest named functions within other functions.

All you need to do is remove the ENTER_FRAME event lsitener on the mouse out.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines