crooksy88
crooksy88

Reputation: 3851

AS3 - Using graphics.clear not working as expected

Would anyone know why using graphics.clear(); in this example is preventing the graphics from being drawn?

e.g. the following code works and the lines are drawn.

var my_shape:Shape = new Shape();
my_shape.graphics.lineStyle(2, 0x00FF00, 1);
addChild(my_shape);

function moveLines():void { 
my_shape.graphics.moveTo(10, 10); 
my_shape.graphics.lineTo(50, 50);
my_shape.graphics.lineTo(100, 100);
}

moveLines();

But if I add the clear() command nothing is drawn.

function moveLines():void { 
my_shape.graphics.clear();  
my_shape.graphics.moveTo(10, 10); 
my_shape.graphics.lineTo(50, 50);
my_shape.graphics.lineTo(100, 100);
}

moveLines();

I'm wanting to animate the line moving so would like to clear the previous drawing before redrawing the lines.

Thanks

Upvotes: 0

Views: 2485

Answers (1)

RIAstar
RIAstar

Reputation: 11912

You have to re-set the linestyle too, so move

my_shape.graphics.lineStyle(2, 0x00FF00, 1);

to your moveLines() method, after the 'clear' of cource.

Upvotes: 2

Related Questions