Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

inverse mask script AS3 > AS2

54 views
Skip to first unread message

gunforhire00

unread,
Dec 8, 2008, 7:38:44 AM12/8/08
to
I have a project that has been built in AS2 but I need to create an Inverse
Mask.
I can do it in AS3 with:

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;
}


whispers

unread,
Dec 12, 2008, 3:27:10 PM12/12/08
to
this is an AWESOME function... thanks.. i was looking at how I could accomplish
this, but wasn't sure how to go about using the bitmap class to do so.. (not
much experience with it I'm afraid)

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

kglad

unread,
Dec 12, 2008, 5:50:41 PM12/12/08
to
there are several restrictions on using masks in flash including each movieclip
can have, at most, one mask and one movieclip can mask, at most, one movieclip.

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.

whispers

unread,
Dec 12, 2008, 11:37:02 PM12/12/08
to
Hey thanks for the reply..

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.


whispers

unread,
Dec 13, 2008, 11:33:22 AM12/13/08
to
hmm..Im still having trouble searching for anything on your mask tip comment:
parent.parent clip (contentContainer)
---parent clip (faceContainer)--
-----lineContainer (holes the shape/object Im using for my source of the
inverse mask
-----maskContainer (empty clip to hold the dynamically created clip form the
inverse mask method above)
-----imageContainer (the place where the dynamically loaded imge gets loaded
into)


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...

kglad

unread,
Dec 14, 2008, 1:58:16 AM12/14/08
to
i'm sorry. i just don't have time to go through all your questions.

i know you should use the concatenatedMatrix to account all the on-stage transformations of your movieclip.

whispers

unread,
Dec 14, 2008, 9:25:40 AM12/14/08
to
the only question there was left, was to expand on your MASKING comment.. as it didnt make sense to me.

assign a parent or whatever it was you were saying.

there was nothing else...

whispers

unread,
Dec 14, 2008, 6:55:27 PM12/14/08
to
gunforhire-

(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

0 new messages