AS3 Pitfalls – stop(); Action Ignored on Nested Movieclip

PROBLEM:

You’ve got a movieclip with a stop action on the first frame. When it appears on-screen, it inexplicably starts playing on frame 2, ignoring frame 1 and your stop action entirely.

The movieclip in question is probably embedded into a parent clip that you’ve dynamically added to the stage from the library using the “new” keyword and “addChild” method.

SOLUTION:

You’re not going to like this. This bug is one of many we’re discovering as we finally make the painful, money-losing transition from AS2 to AS3 for all our future projects. You have two options:

  1. Put an extra frame at the beginning of the movieclip, with the stop(); action on frame 2. This solution completely stinks, but welcome to our brave new world where Adobe ignores the needs of designers and caters only to people who code absolutely everything and don’t use the timeline.
  2. In my case, i was able to stop the clip on frame 1 by making an explicit call from the method that attached the parent clip, like so:
1
2
3
4
var parentClip:MovieClip = new ParentClip();
addChild(parentClip);
parentClip.childClip.stop();
// where childClip is the one that's giving us problems

Further Reading:

Here are some of the places i hit on my merry way to finding the so-called answer to this problem:

Flashkit: AS3 stop(); code not working??

actionscript.org: AS# stop(); doesn’t work

5 thoughts on “AS3 Pitfalls – stop(); Action Ignored on Nested Movieclip

  1. Maria Duhagon

    Thanks!! I’m starting to code AS3 and found this same ‘weird behavior’ in one of my projects…
    You saved me a lot of head scratching time with your post!

    Reply
  2. Jason

    Dude, thanks for this, didn’t even occur to me to stop the playhead in the code that adds the movieclip. kept wondering why the playhead wouldn’t stop even though the stop(); function was on the timeline.

    Reply
  3. Yan

    Thanks a bunch! I should let you know that I am a very experienced AS coder (not a designer) but even this way I wasted a LOT of time because this stupid bug. It never passed to my mind to add an extra frame with an extra stop() because it sounded completely illogical to me. Thanks again for putting a light over that!

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *