clipToMask.cacheAsBitmap = true
clipToMask.mask = inverseMask(mask_mc)
function inverseMask(mc:MovieClip) {
var _BMP:BitmapData = new
BitmapData(stage.stageWidth,stage.stageHeight,true,0xFFFFFFFF)
var invert:ColorTransform = new ColorTransform(0,0,0,1)
var matrix:Matrix = new Matrix()
matrix.translate(mc.x,mc.y)
_BMP.draw(mc, matrix,invert)
_BMP.threshold(_BMP,new Rectangle(0,0,_BMP.width,_BMP.height),new
Point(0,0),"<",0xFFFFFFFF,0x00FF0000)
var BMP:Bitmap = new Bitmap(_BMP)
var maskMC:MovieClip = new MovieClip()
maskMC.addChild(BMP)
maskMC.cacheAsBitmap = true
this.addChild(maskMC)
mc.visible = false
return maskMC
}
BUT.....
I need to convert this to AS2. The project is almost built, so rewriting the
whole job in AS3 isn't an option any longer.
Can anyone help?
So far I have (see below) but it doesn't work.
import flash.display.BitmapData;
import flash.filters.BitmapFilter;
import flash.filters.ColorMatrixFilter;
import flash.geom.ColorTransform;
import flash.geom.Matrix;
clipToMask.cacheAsBitmap = true
clipToMask.setMask(inverseMask(mask_mc));
function inverseMask(mc:MovieClip) {
trace("mask: " + mc);
var _BMP:BitmapData = new
BitmapData(stage.stageWidth,stage.stageHeight,true,0xFFFFFFFF)
var invert:ColorTransform = new ColorTransform(0,0,0,1)
var matrix:Matrix = new Matrix()
matrix.translate(mc.x,mc.y)
_BMP.draw(mc, matrix,invert)
_BMP.threshold(_BMP,new Rectangle(0,0,_BMP.width,_BMP.height),new
Point(0,0),"<",0xFFFFFFFF,0x00FF0000)
var BMP:BitmapData = _BMP.clone();
var maskMC:MovieClip = this.createEmptyMovieClip("mc",
this.getNextHighestDepth());
maskMC.attachBitmap(clonedBitmap, this.getNextHighestDepth());
maskMC.cacheAsBitmap = true;
mc._visible = false
return maskMC;
}
I do have a question though....that maybe you can help or suggest a direction
for me to pursue.
I am using function in/on a several times nested clip.
I am loading an image dynamically, (upon loadInit() I am then attaching that
image as a bitmap so it scales nicer than just loaded .jpg)
I have my mask clip nested as well, but above the imageContainer clip..
all these nested clips, are under a mask on its own..(so that any image loaded
that may be bigger then my display area is masked, and not bleeding over)...
however if this nested clip is masked..and I use this function on the clips
inside of this container.. it does work correctly..
Any ideas?
Thanks
there are ways to work around the masking more than one movieclip by assigning
each movieclip you want to mask, one parent movieclip.
when using the bitmapdata draw() method, you "draw" the object without any of
the on-stage transformations (including alpha, position, rotation, scaling
etc). to create a bitmap that reflects the on-stage transformations you need
to use the other parameters (like matrix, color matrix) of the draw() method.
I guess I'll try to tackle the positioning (off-set) problem first... like I
said I havent used the bitmap class much.. so Im not really sure how to go
about fixing it using the matrix/color matrix options you outlined..
I was actually just playing with the threshold line and trying different
parameters for the new Rect() and new Point)( params..but it gave me mixed
results at best... (like only the lower & right side of the shape/mask I
drew..)
so if I load an image into a clip..and move that clip before running the
inversedmask() method above.. I need to look into tweaking the draw() line in
the inversedMask()?
If I didnt mention before..this is AS2...
so do I editt his draw line/snippet of code:
_BMP.draw(mc, matrix, invert);
and add to parameters to it? or create anew one your saying?
sorry for being thick here..
thanks again for replaying.
using the tweak inversedMask() function above... I create my inversedMask
inside of the maskContainer clip...which does the inversed mask and masks the
imageContainerClip...
all working fine...
but I want to add a mask to either the parentClip (faceContainer), or even its
parent (the contentContainer) clip..
so obviously when I scale the face container it doesnt bleed out of the
display area...
however when i apply a mask either manually or through AS to either of these
clips, as soon as I load the image... draw my shape for the source of the
inverse mask, and then actually click the button to execute the inversedMask()
function.. the whole screen goes blank..
I remove the 'parent' masks and it works exactly as it should..
suggestions or things I can search for...
i know you should use the concatenatedMatrix to account all the on-stage transformations of your movieclip.
assign a parent or whatever it was you were saying.
there was nothing else...
(if your still around per chance)--
Im wondering if you have tried (and been successful) in using a parent mask in
any way in conjunction with your method above?
whenever I try to add a mask to a parent clip..(that holds the inversedMask
and the masked nested clips... the whole thing goes 'blank' (masked out).
any ideas?
thanks