Dynamic Mask

Moving From AS2 to AS3: Creating Dynamic Masks

Tags: , , ,

Dynamic mask objects have been key to many Flash project’s success. When it comes to migrating over from AS2 to AS3, you’ll find that things have changed as the method “setMask()” in AS2 is now a property called “mask”. In this next edition of the Moving From AS2 to AS3 series, I will be comparing the two solutions and offering an efficient solution to creating dynamic masks using AS3.

Comparing AS2 to AS3

Setting masks dynamically using ActionScript 2.0

myMC.setMask(maskObject);

Setting masks dynamically using ActionScript 3.0

myMC.mask = maskObject;

So as you can see the syntax hasn’t changed much, however, personally I feel that AS3′s implementation is a bit more literal making it easier to understand.

Creating your masking objects as Sprites

While in ActionScript 2.0 there was no better of a solution than to create your masking object as a MovieClip. With the introduction of the Sprite object in ActionScript 3.0, creating your masking objects as Sprites is a far more efficient solution.

Since a mask object does not require a timeline, using a Sprite instead of a MovieClip simply makes more sense. Below is an example where a Sprite is used in place of a MovieClip:

// Create mask
var maskObject:Sprite = new Sprite();
maskObject.graphics.beginFill(0xFF0000);
maskObject.graphics.drawRoundRect(myMC.x, myMC.y, 453, 290, 20);

// Apply mask
myMC.mask = maskObject;

Download Example File

I hope this helps in your migration over into  AS3.  If there is something in particular you want to add or see with the Moving From AS2 to AS3 series, feel free to contact me via the contact page.

Related Posts

CASA Lib

CASA LIb’s FrameUtil: Extending the Functionality of the Flash Timeline

CASA Lib ArrayUtil

CASA Lib’s ArrayUtil: Sorting, Searching and Manipulation of Arrays Made Easy

AS3 Library External Resource

How To: Implement an AS3 Library into Your Flash Environment

ActionScript 3 Logo

Moving From AS2 to AS3: A Handy List of Resources

5 Comments

  1. Ben

    03.31.2009

    Reply

    Thanks for this quick explanation. That’s awesome from you to deliver downloadable content.

    • Angel

      03.31.2009

      Reply

      No Problem!

  2. Mémé

    08.18.2009

    Reply

    hello there and thanks i’ve just understood the way masks are set. Yesterday i was tryin to deal with masks by putting them on the timeline over the textfield, but it ended crashing flash all the times. Weird.

    How do i make this mask tween so that it makes as if a text under is being written?

    Regards.

  3. yea

    05.07.2010

    Reply

    addChild is not necesairy?

Leave a Reply









Latest Theme From WooThemes

Unsigned

By WooThemes

Unsigned is a hugely powerful, cleverly developed, yet super easy theme to use for musicians and bands looking to showcase their music, tours, photos, videos and band members all from within WordPress. It even allows you to sell your albums and merchandise thanks to the WooCommerce integration. It truly is a massive theme that will cover your every need.

Theme Categories: Multimedia, Responsive

Latest Tweets