Search code examples
actionscript-3flashadobemaskmovieclip

Is It possible to make a Transparent Mask like making an window, on AS3 Flash?


I want to have a movieclip make a hole on another movieclip, like putting a window on a wall. I can make a mask that has the same effect as right-clicking a layer and masking it, but that is not what I want. I want to make a transparent hole.

I have tried something like this:

mc1 = new green(); 
mc2 = new blue(); 

mc2.blendMode = BlendMode.ALPHA; 

addChild(mc1); 
addChild(mc2); 
mc2.cacheAsBitmap = true; 
mc1.mask = mc2; 

And this:

mc1.cacheAsBitmap = true;

mc2.cacheAsBitmap = true;

mc1.setMask(mc2);

First problem: The code gives me errors. Second problem: Doesn't make a hole on the movieclip, just does a normal mask.


Solution

  • Here is your code, revised:

    var mc1 = new green(); //included var before variable name
    var mc2 = new blue();
    
    mc2.blendMode = BlendMode.ERASE; //this masking shape will ERASE what's below it
    MovieClip(root).blendMode = BlendMode.LAYER; //setting root to LAYER so this works
    
    addChild(mc1); 
    addChild(mc2); 
    mc2.cacheAsBitmap = true; 
    

    It appears you are trying to create an 'inverted mask,' where the mask reveals everything under it except for where it is located. This effect can be achieved by giving your mc2 a blend mode of BlendMode.ERASE instead of BlendMode.ALPHA.

    Check out this article for reference.