PDA

View Full Version : Detecting when a MovieClip ends


Molybdenum
08-19-2009, 04:59 AM
I'd like to remove a MovieClip instance from the main timeline (and do a few other things) once that movie is over.

Scenario: I've got a frog catching a fly with his tongue. Once the frog-tongue movie clip is over, I want to remove both the tongue, and the fly from the timeline. Both the tongue and the fly are MovieClip objects. The tongue animation starts based on a TimerEvent. I'd like to say something like: when the tongue MovieClip ends, call removeChild() on tongue and fly.

Any ideas how to do that? I tried:

tongue.addEventListener(MotionEvent.MOTION_END,aft erMotion);

function afterMotion(m:MotionEvent)
{
trace("Motion over");
}
But the event never seems to fire...

ASWC
08-19-2009, 12:31 PM
on the last frame of the animation make a key frame and add this:
dispatchEvent(new Event("animation_done"));
then you can listen to this event like this:
tongue.addEventListener("animation_done",afterMotion);

Molybdenum
08-20-2009, 03:08 AM
Oh, I didn't realize you could do that. That's a handy tool to have around for message passing. Thanks for the help!