Klye
Klye

Reputation: 104

AS3: Change Lines Style

So I have gotten my line to draw and follow the mouse cursor around, but I think the default line style is pretty dull. So I was wondering if there was a way to change the default brush style on the line to something else, like another brush for example.

function activateDraw(event:MouseEvent):void{
    myshape.graphics.moveTo(mouseX, mouseY);
    addChild(myshape);

    stage.addEventListener(MouseEvent.MOUSE_MOVE, lineDraw);
    stage.addEventListener(MouseEvent.MOUSE_UP, stopDraw);
}

function lineDraw(event:MouseEvent):void{
    myshape.graphics.lineTo(mouseX, mouseY);
    event.updateAfterEvent();
}

function stopDraw(event:MouseEvent):void{
    stage.removeEventListener(MouseEvent.MOUSE_MOVE, lineDraw);
    stage.removeEventListener(MouseEvent.MOUSE_UP, stopDraw);

    myshape.graphics.clear();
    myshape.graphics.lineStyle(12, 0x99CC33);
}

stopDraw(null);

Upvotes: 1

Views: 602

Answers (1)

BadFeelingAboutThis
BadFeelingAboutThis

Reputation: 14406

The stroke styles that are found in Flash Professional are not accessible through code as an option for a graphics lineStyle. They can be re-created through code but it would involve lots of tweaks to the cap styles and drawing a line for each dash (or dot) etc.

You could find some pre-made helper classes to do much of this, like this one for instance: http://andywoodruff.com/blog/drawing-dashed-lines-with-actionscript-3/

You can also add filters to make your lines more interesting.

myShape.filters = [new BlurFilter()];

That would give your line a soft edge. There are many filters built in to choose from and you can add as many as you want to the filters array property of a display object. (though beware of performance bottlenecks when getting too crazy with filters).

Upvotes: 1

Related Questions