PDA

View Full Version : drawing dynamic mask problem?


HW2002
12-22-2007, 10:45 AM
Hi,

I'm trying to draw dynamic mask but it is not working as supposed?

I can only get it to work this way, when you move the mouse it will draw white lines on the stage, after that you can click on the mouse to apply the lines on the mask? Why cannot I apply the mask and draw the lines dynamic?

Thanks for any help :)


public class Main extends Sprite {

private var child:Shape = new Shape();
private var masked:Sprite = new Sprite();
private var num:Number = 0;

public function Main():void {
addChild(child);
background.mask = masked;
addEventListener(MouseEvent.MOUSE_MOVE, mouseMove);
addEventListener(MouseEvent.MOUSE_DOWN, mouseDown);
}

private function mouseMove(m:MouseEvent):void {
child.graphics.lineStyle(2, 0xFFFFFF);
child.graphics.lineTo(mouseX, mouseY);
}

private function mouseDown(m:MouseEvent):void {
masked.addChild(child);
}
}

HW2002
12-24-2007, 10:11 AM
someone must have done dynamic masking?

fentunfont
12-25-2007, 01:34 PM
you're adding "child" twice. that can be an issue.

to do dynamic masking, youd do something like:



var background:Sprite = new Sprite();
var mask:Sprite = new Sprite();

addChild(background);
addChild(mask); //because masks have issues with scalign if you dont do this

background.mask = mask;

mask.graphics.beginFill(0x000000, 1);
mask.drawRect(0, 0, 100, 100);
mask.endFill();

//or whatever drawing you want to do



i think because you add child twice it messes with the masking... perhaps something else is wrong too but thats what jumps out at me.