Using a dynamically loaded movie as a mask in Flash 8 using Actionscript

| |

In Flash 8, I had a movieclip "artwork" that I wanted to mask with another movieclip "mcdots" from actionscript. The typical syntax is:

mcMaskee.setMask(mcMask);
// or in my case:
artwork.setMask(mcdots);

The trouble is when I dynamically load the movie "maskdots," something weird happens, and the mask won't work:

maskdots.loadMovie("dots.swf");
artwork.setMask(mcdots);

The movie loads as expected, but the dots simply overlay rather than mask.

The solution was to delay or separate the process of loading the mask and applying it. To avoid a messy load checkstate routine, I simply used a basic enclosure called from a setTimeout (years of javascript taught me that):

setTimeout(function() { artwork.setMask(mcdots); }, 0 );
mcdots.loadMovie("dots.swf");

Now, I'm not 100% certain why this works, but I believe it has something to do with the time at which things are evaluated, when they are computed, and when they are rendered. I posted the same solution to Macrodobe Live Docs as well. Hope it helps someone.

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

this helped quite a bit

solved my problem.

thanks

great!

So glad it helped-- thanks for the feedback!

-bronius

yay!

wow, i searched for this all over the internet, and your code was the only one that worked for me! yay! thank you so much :D

Glad I could help with enclosures in Flash / Actionscript

Hey, thanks for the feedback. If you can think of any other good keywords to stuff this resource to shorten any future wayward developer's journey, I'm all ears... cheers.