PDA

View Full Version : Mask in movieclip



ozkanb
May 15th, 2009, 10:44 AM
i have to make 4 movieclips in the stage and each movieclip must have a different mask.

so i need to make the mask in the movieclips.

now i tried some things but it doesn't work...

any ideas how i can make a mask in a movieclip, and after that, i have to tween the movieclip from left to right and then it has to disappear.

thx for any help, i'm really desperate

cbeech
May 15th, 2009, 11:30 AM
in AS3 you can dynamically draw a mask within the mc and apply it to 'itself' using the mask property. so in the constructor of the mc's class file, do something like this:



public function myMC():void {
var clipMask:Sprite = new Sprite();
clipMask.graphics.beginFill(0x000000);
clipMask.graphics.drawRect(0,0,width,height);
clipMask.graphics.endFill();
addChild(clipMask);
mask = clipMask;
}

then to 'tween' the clip - there are several different tweening engines - but to use the native flash tween, you could create a method in the clips class file to slide off stage when called, something like:



public function slideMC():void {
var tx = new Tween(this, 'x', Strong.easeOut, this.x, stage.stageWidth, 1, true);
tx.addEventListener(TweenEvent.MOTION_FINISH, removeMC);
}

public function removeMC(e:TweenEvent):void {
parent.removeChild(this);
}

also don't forget to import the needed classes to tween

import fl.transitions.Tween;
import fl.transitions.TweenEvent;
import fl.transition.easing.*;

ozkanb
May 15th, 2009, 12:11 PM
allright thx for your reply, i'll try that

what's mask in funciton myMC
mask = clipMask;

cbeech
May 15th, 2009, 12:22 PM
you're welcome - 'mask' is the Display Object property that you call to apply a masking object to the object - in this case one doesn't need to 'target' an object (eg. like - myMC.mask = blah) since the operation is being performed within the scope of the object. one could say 'this.mask = blah' - but it is 'unnecessary' to use the 'this' keyword and is mostly a stylistic preference.