Silvio Luis
Silvio Luis

Reputation: 193

How to make a Mask in AS3

I have a duvifa that is:

I wonder if it is possible to make a mask in a movieClip the way it is below:

If this image would be the beginning of the game.

enter image description here

When the user clicks on the screen, a type of cream would be created, but not like he would extend all over the stage, but only in my way.

enter image description here

As below:

enter image description here

And also like to know if I can get a percentage of what was filled in the form, to see if the user has filled at least 40%.

Thank U.

Upvotes: 0

Views: 2316

Answers (1)

BadFeelingAboutThis
BadFeelingAboutThis

Reputation: 14406

Here is a quick example using flashPro, assuming you have your shape graphic as an import .png library object with an export for actionscript class of MC.

import flash.display.Shape;
import flash.events.Event;
import flash.display.BlendMode;

var mc:MC = new MC(); //the background image
addChild(mc);

var drawing:Shape = new Shape();  //drawing foreground
addChild(drawing);

var mcMask:MC = new MC(); //mask version of background image
addChild(mcMask);

var outerMask:Shape = new Shape(); //this object masks the areas outside the bounds of mcMask object
outerMask.graphics.beginFill(0);
outerMask.graphics.drawRect(0,0,mcMask.width,mcMask.height);
outerMask.graphics.endFill();
addChild(outerMask);

drawing.mask = outerMask; //the mask to the shape whose dimensions equal the image mask

mcMask.blendMode = BlendMode.ALPHA; //this tells the mask graphic to make things underneath it use the same alpha data as this image.  This works will with PNG masks.
this.blendMode = BlendMode.LAYER; //the parent needs to have a blend mode of LAYER for it to work properly

stage.addEventListener(MouseEvent.MOUSE_MOVE,draw);

function draw(e:Event):void {
    trace("draw");
    drawing.graphics.beginFill(0x0000FF);
    drawing.graphics.drawCircle(mouseX,mouseY,10);
    drawing.graphics.endFill();
}

Upvotes: 1

Related Questions