Can you change Line Style after Its drawn?

Can you change the “lineStyle” of a line once it’s been drawn?
In this case, I’d like to change the alpha once the user is done drawing each line.
From what I am finding, “lineStyle” only sets the values to the line BEFORE you begin drawing.
(Ignore the cancel button. It’s for later.)

var lines:Array<Shape> = new Array<Shape>();
var currLine:Int = 0;	
var drawing:Bool = false;

public function Update(e:Event)
{
	if (drawing == true) { lines[currLine].graphics.lineTo (mouseX, mouseY); }
}
public function ClickHandler(m:MouseEvent)
{
	var clicked:Bool = false;
	if (cancelBut.hitTestPoint(mouseX, mouseY, true) && cancelBut.visible == true && clicked == false) {
		clicked = true;
	}
	else {			
		lines.push(new Shape());
		addChild(lines[currLine]);
		lines[currLine].graphics.lineStyle(5, 0x000000, 1); //sets the size, color, and alpha
		lines[currLine].graphics.moveTo (mouseX, mouseY);
		drawing = true;
	}
}
public function MouseUp(m:MouseEvent)
{
	if (!cancelBut.hitTestPoint(mouseX, mouseY, true) && cancelBut.visible == true) {
		drawing = false;
		currLine++;
	}
}

var alpha = 1.;
for (i in 0...10) {
	alpha -= 0.1;
	this.graphics.lineStyle(1, 0xff0000, alpha);
	this.graphics.moveTo(i * 100, 100);
	this.graphics.lineTo(i * 100 + 100, 100);
}

Is that so? If you want to modify, you can call lineStyle multiple times.

1 Like

Yeah, I tried that upon calling MouseUp (basically fading the line after it is drawn, but for some reason it never changed. I didn’t use “this” in front of it though. I’m an amateur at best, learning from the web. What does the “this” mean when added to the front of the display object?

this=currentClass itself

1 Like

You can’t change the alpha of the line after it is drawn. You need to clear what you’ve already drawn and redraw it again with the new alpha.

You can still change the alpha of the movieclip container.

Luckily, my mind slowed down and I remembere I could change the alpha of the array element itself rather than the lines style. For example, lines[0].alpha = .5.

Yes, that’s true. If all you’ve drawn is the line, you can change the alpha property of the display object. However, if you’ve drawn a variety of lines and fills, and some shouldn’t have a different alpha, for some reason, you’d generally need to redraw them. Alternatively, you could draw some graphics to separate display objects, which would allow you to change the alpha of some, but leave others as-is.

1 Like