How to move the mask without the masking area that it has created
Im trying to position a masking area at a certain location where it will mask a fraction of an object (myRainBow), and then move the mask without moving the masking area.But the code that i have does exactly the opposite -> it moves the masking area with the mask itself.
My problem put in other words :
I have a beautiful picture, but i want to move the picture at a different location on my living room wall.So where ever i move the picture (top corner, left corner , bottom-center corner ,etc.) it (the content of the picture itself) will not change, only its location of the picture in my living room.
How do i do that with as3 code, cause i have so far only this and it is not doing what i want it to do
private var masker:Shape = new Shape();
private var maskerBoarder:Shape = new Shape();
private var container:Sprite = new Sprite();
private var myRainBowPicture:Sprite = new Sprite();
private var m:Matrix = new Matrix();
public function MainMask()
{
if (stage) init();
else addEventListener(Event.ADDED_TO_STAGE, init);
}
private function init(e:Event = null):void
{
removeEventListener(Event.ADDED_TO_STAGE, init);
this.addChild( container );
//create the gradiant
m.createGradientBox( 400, 300, 0, 0, 0);
myRainBowPicture.graphics.beginGradientFill(GradientType.LINEAR, [ 0xFF, 0xFF00FF, 0xFF0000], [1, 1, 1], [0x0, 0x7F, 0xFF], m , SpreadMethod.PAD, InterpolationMethod.LINEAR_RGB, 0);
myRainBowPicture.graphics.drawRect(stage.stageWidth * 0.5 - 200 ,stage.stageHeight * 0.5 - 150, 400, 300);
myRainBowPicture.graphics.endFill();
addChild(myRainBowPicture);
masker.graphics.beginFill( 0x00ff00 );
masker.graphics.drawRect( 0, 0, 200, 100 );
masker.graphics.endFill();
container.addChild( masker );
maskerBoarder.graphics.beginFill( 0, 1 );
maskerBoarder.graphics.drawRect( 0, 0, 200, 100 );
maskerBoarder.graphics.beginFill( 0x00ffAA, 0.5 );
maskerBoarder.graphics.drawRect( 2, 2, 194, 96 );
maskerBoarder.graphics.endFill();
maskerBoarder.graphics.endFill();
container.addChild( maskerBoarder );
myRainBowPicture.mask = masker
container.addEventListener(MouseEvent.MOUSE_DOWN, onClick)
container.buttonMode = true;
stage.addEventListener(MouseEvent.MOUSE_UP, drop);
}
private function onClick(e:MouseEvent):void
{
container.startDrag();
}
private function drop(e:MouseEvent):void
{
stopDrag();
}
