View Full Version : Idiotic masks : )
sekasi
March 23rd, 2009, 02:55 AM
Look, this has annoyed me for a while and I don't really know what the deal is. Anyone that knows the answer will defo be on my favorite people list for a while.
In the Flash IDE, you can easily mask two layers with another layer, effectively masking multiple sprites with the same sprite.
Is this really not possible with actionscript? And no, I don't want to create a holder sprite with all of those inside and then mask that holder sprite. And no, I don't want to have two masks.
Seriously what's the deal, this has annoyed me so many times and I swear to god there's a ridiculously easy answer but I can't see it. :whistle2:
Krilnon
March 23rd, 2009, 03:18 AM
So, you basically want to do something like this:
s1.mask = m;
trace(s1.mask); // [object Sprite]
s2.mask = m;
trace(s1.mask); // null
…except that you want s1 to keep the mask even after it has been assigned to s2?
If so, I don't know of a way to do that. I just noticed that a note was added to the mask property description in the language reference for Flex 3.3 that wasn't in the CS3 documentation:
Note: 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.
sekasi
March 23rd, 2009, 04:24 AM
That's pretty much the intention yes.
It's odd how that works in the IDE however.. I guess there's some holder fishyness going on when that happens ?
Anogar
March 23rd, 2009, 05:45 PM
Must be. :-/
Krilnon
March 23rd, 2009, 06:05 PM
I looked into this a little bit and I suspect that the IDE layer masks are clipping layers:
Clipping layers
Flash Player supports a special kind of object in the display list called a clipping layer. A character placed as a clipping layer is not displayed; rather it clips (or masks) the characters placed above it. The ClipDepth field in PlaceObject2 specifies the top-most depth that the clipping layer masks.
For example, if a shape was placed at depth 1 with a ClipDepth of 4, all depths above 1, up to and including depth 4, are masked by the shape placed at depth 1. Characters placed at depths above 4 are not masked.
PlaceObject2 is a SWF tag.
IQAndreas
March 23rd, 2009, 06:09 PM
I don't understand why they would set that limitation. Seems illogical, and impractical.
Would it still work for your specific project to use clone() or draw() to create a duplicate of the mask, and use this duplicate as a mask for the other objects?
You would also have to compensate for if one of the original mask resizes or changes, this might have to be updated for all child masks.
If you really wanted to, you could create a new class that handles this:
public class MaskableMovieClip extends MovieClip
{
public function MaskableMovieClip():void
{ ... }
private var _mask:DisplayObject
public override function get mask():DisplayObject
{ return _mask; }
public override function set mask(newMask:DisplayObject):void
{
this._mask = newMask;
this.updateMask();
}
public function updateMask():void
{
super.mask = this._mask.draw();
}
}
It would be a bit of a hassle, since you would have to make sure that updateMask() is called every time there are any changes to the mask or MaskableMovieClip. Sadly, flash does not dispatch enough events by default to tell you when values have changed.
It should work theoretically, but I haven't actually tested it. At first I tried using clone(), but then I realized that it is not a method of the DisplayObject.
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.