Thursday, December 24, 2009

Dynamic mask in Actionscript 3

In this Flash tutorial you will learn how to create a dynamic draggable mask in Actionscript 3.0.
in AS3 the mask property is used, which looks like “img_container.mask = maskObject”. The “img_container” is the object which gets masked, and the “maskObject” is the actual mask itself.

Dynamic mask in Actionscript 3

Step 1:
Open an Actionscript 3.0 file.
Import the image you wish to use as your masked background by selecting File > Import > Import to Stage.

Step 2:
Select your image and convert it into a symbol by pressing F8. Give your image an appropriate name, check movie clip and click ok. Then select your movie clip and give it the instance name: img_container.

Step 3:
On the timeline insert a new layer called “Action”,abd paste the code below:

//
function applyMask(){
var maskObject:Sprite = new Sprite();
maskObject.graphics.beginFill(0xFF0000);
maskObject.graphics.drawRoundRect(img_container.x, img_container.y, img_container.width, img_container.height, 10);
addChild(maskObject);
img_container.mask = maskObject;
}
applyMask();

No comments:

Post a Comment