Add Mask to Display List when using StageScaleMode.SHOW_ALL

I spent a few hours going nuts with this one today, so save yourself some time by reading this post. Suppose that you have some content that you want to scale when the flash player is re-sized. Suppose also that you have added this line in order to accomplish it:

1
stage.scaleMode = StageScaleMode.SHOW_ALL;

Now imagine that you test that program and are stretching the window around. Everything seems to be working great, except that there are some items that you have used masks on and the mask is floating around all over the place!

There is a VERY simple fix for this. In AS3 projects you MUST add the mask itself to the display list, or it will NOT scale with your project.

So, for example:

1
2
3
4
5
6
7
8
var myMask:Sprite = new Sprite();
myMask.graphics.beginFill(0x0000FF);
myMask.graphics.drawRect(0,0,100,200);
myMask.graphics.endFill();

// YOU MUST FIRST ADD IT TO THE DISPLAY LIST OR IT WILL NOT SCALE WITH THE CONTENT!!!
addChild(myMask);
myContent.mask = myMask

I figured this out by just trying it on a hunch. I’m guessing that by adding it to the display list it has something to reference for what size it is ‘supposed’ to be. When you simple add a mask to a display object’s mask property, it does not make it a child of that object automatically; therefore it does not scale with it. Weird if you ask me, but there it is. I hope this helps!

Share on FacebookShare on Google+Share on StumbleUponTweet about this on TwitterEmail this to someone

Facebook comments:

2 thoughts on “Add Mask to Display List when using StageScaleMode.SHOW_ALL”

  1. Glad to see another post!

    I had the same problem, solved it with nearly the same solution…
    Only thing that was different was the name of the mask… Well, maybe the content as well.

    I look forward to seeing more posts!

  2. I’m glad to hear it! I post these little tidbits in hope that I can save someone else hours of frustration and searching. Unfortunately people have to search for my site too, but it does get a surprisingly high number of hits on subjects like this one.

Leave a Reply