Flash Bug with keyframe masks and MovieClips

October 2nd, 2007 by Steven Sacks

It seems lately that all I'm posting about are bugs, heh. Well, this one is an oldie but a goodie and I'm surprised it still hasn't been fixed.

There is a bug in Flash where if you have a mask with keyframes, any MovieClips being masked by it that have classes assigned to them will have their constructors fired again when the mask keyframes hit. The MovieClip has no keyframes, just the mask layer.

As far as I'm concerned, this is a bad bug. It's been around since Flash 7 and it's one of those bugs that causes you to get frustrated trying to figure out why your movie is breaking because it's not obvious. I personally have forgotten about it and had it happen to me again and spent quite awhile trying to determine what the issue is, only to remember after I discover what's happening.

Part of the reason for this post is so I never forget again. Part of it is a hope that Adobe will fix it (wishful thinking).

It is easy to make a trivial example to show this happening. Here's how.

Make a class that extends MovieClip:

class Test extends MovieClip
{
    function Test()
    {
	trace("frame: " + _parent._currentframe);
    }
}

Now draw a square on the stage and make it into a MovieClip. In the library, link it to the Test class.

Draw a circle above the square, add two key frames at frame 11 and 20, then turn it into a mask layer to mask the MovieClip.

Put a stop() action on Frame 20.

Mask Bug Timeline

Test the movie. In the output panel, you will see the Test class constructor fire three times, on frames 1, 11, and 20.

This buggy behavior can cause all kinds of issues, not least of which is if you addEventListeners in the constructor, it can lead to your MovieClip receiving those events multiple times, which leads to broken behavior you can't account for.

The "solution" is to make the mask into a MovieClip and put the keyframes inside of that MovieClip timeline. Animators and designers don't really appreciate that, however, because they can't visually see the effect of changes in their mask animations on the content by scrubbing, they have the test the movie, which can take a long time if there are a lot of assets or embedded fonts in the file.

I hope this guide helps anyone who has this issue and maybe convinces Adobe to fix it.

Posted in Bugs

5 Responses

  1. Ming

    Another work-around solution is to use SetMask()

  2. Martin

    Agreed, it is a ridiculous bug to still exist, and although both these solutions will work, they don't allow for the use of the mask as you would want it.

    The point of using graphics and timelines for animators is to perfectly sync timelines - 2 MovieClips cannot be expected to stay together over any period of time.

    Personally, I'd go so far as to use Fuse to control both the timelines in the MovieClips - more code, more hassle, it should just work.

  3. Steven Sacks

    setMask() avoids the bug exactly how I outlined since it requires that you make your mask into a MovieClip. At that point, though, you're just dodging the issue and the animator still can't preview their work.

  4. James

    I know this was posted in Octobver, but I found it interesting enought to merit a post.
    Maybe I'm missing something obvious, but couldn't a compromise be to convert the mask into a graphic and set it to 'Play Once'. In that regard it won't cause the constructor to be called multiple times, and the animators can view their mask through the timeline rather than waiting to publish?

  5. Phil

    You absolute legend! I've been searching for a solution to this for aaaages (it took me this long to realise that the problem was related to keyframes) - your workaround worked first try. Thanks!

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.

About Steven Sacks

I am a professional Flash developer with over 13 years of programming experience. I have consulted for high-profile agencies and companies in San Francisco, Los Angeles, Atlanta and New York, and developed numerous award-winning websites and rich internet applications for clients including Adobe, Fox Sports, FX Networks, Anheuser-Busch, GE, DirecTV, ESPN, The Weather Channel, Home Depot, and Coca-Cola.

I am the author of the open-source Gaia Framework for Adobe Flash, which dramatically reduces development time and makes developing Flash sites much easier.