mask/setMask() 101

1. setMask() will not affect the display of device fonts. They will be drawn regardless;

2. setMask() takes priority to timeline mask layers;

3. Movieclip nested inside a container mc can mask the container mc (which “includes” itself) by calling setMask() !

AS3 NOTE: setMask is deprecated in AS3 in favor of DisplayObject.mask property.

For a mask to be effective, it doesn’t need to be added to the display list. But you would _need_ to include it in “an active part of the display list” in the following cases:

  • To ensure that masking works when the Stage is scaled;
  • To be able to scale a mask object;
  • To be able to drag a mask Sprite object (by calling its startDrag() method)

A single mask object cannot be used to mask more than one calling display object. When the mask is assigned to a second display object, it is removed as the mask of the first object, and that object’s mask property becomes null.

A mask or maskee display object cannot take any mouse event, while its parent container object _can_. This means if both a mask object and its container are listening to a mouse click event, when you click on the maskee where there is no other content, the container handler will respond while the mask handler won’t.

this.stage.scaleMode = StageScaleMode.NO_SCALE;
this.stage.align = StageAlign.TOP_LEFT;
this.stage.showDefaultContextMenu = false;

//mask
var w:Number = 854;//stage.width;
var h:Number = 480;//stage.width;
var square:Shape = new Shape();
square.graphics.beginFill(0xFF0000, 1);
square.graphics.drawRect(0, 0, w, h);
square.graphics.endFill();
//this.addChild(square);

this.mask = square;

//frame
var frame:Shape = new Shape();
frame.graphics.lineStyle(1, 0x9E0000, 1);
frame.graphics.beginFill(0xFFFFFF, 0);
frame.graphics.drawRect(0, 0, w-1, h-1);
frame.graphics.endFill();
this.addChild(frame);

Advertisements

Tags: ,

One Response to “mask/setMask() 101”

  1. Simon Says:

    Hi could you give an example in regards to option 3. Using it in a custom class scenario i.e.

    this.my_mc = this.createEmptyMovieClip(“my_mc”, this.getNextHighestLevel());
    this.my_mc.img = this.my_mc.attachMovie(“my_img”, “img”, this.my_mc.getNextHighestLevel());
    this.my_mc.my_mask = this.my_mc.createEmptyMovieClip(“my_mask”, this.my_mc.getNextHighestLevel());

    this.my_mc.img.setMask(this.my_mc.my_mask);

    Cos it ain’t working for me???

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s


%d bloggers like this: