Actionscript 3 Image Mask Eraser


Intro

This a very easy and quick tutorial. You'll learn how to create an image mask eraser like the above.

Procedure

1. Import an image you want to use.

2. Convert the image into a movie clip (name it whatever you want).

3. Give it an instance name of "imageMC".

4. Create an actions layer and type the following.

//This container contains all the mask graphics
var container:Sprite = new Sprite();

addChild (container);

//Set the container to be the image's mask
imageMC.mask = container;

//Set the starting point
container.graphics.moveTo (mouseX, mouseY);

addEventListener (Event.ENTER_FRAME, enterFrameHandler);

/*Draw a new rectangle in each frame and add it onto the container
NOTE: you can use all kinds of shapes, not just rectangles! */
function enterFrameHandler (e:Event):void {
	container.graphics.beginFill(0xff00ff);
	container.graphics.drawRect(mouseX-50, mouseY-50, 100, 100);
	container.graphics.endFill();
}

Mouse.hide();

5. You are done, test your movie!

Bookmark and Share