Systeme D

February 5, 2009

Dotted/dashed line in ActionScript 3

Getting dotted lines in ActionScript seems to be one of those old chestnuts. The ever-resourceful Senocular has a neat ActionScript 2 solution, ported to ActionScript 3 here.

It’s pretty good, but wasn’t quite right for my needs. First of all, it spends quite a lot of time dealing with curves, which I don’t need – polylines are enough. Secondly, it just lets you define one ‘on’ length and one ‘off’ length, so you can do 6px on and 3px off, but not (say) 6 3 1 3. 

So here’s my 2am answer. Pretty compact, seems to work happily. I’ve not genericised it into a DashedLine class or such because that wouldn’t work for my project and I have no reason to think it will for yours, but feel free to do so. I think it’s a bit shorter than Senocular’s, too, though that might just be due to multi-statement lines…

dashedline.as


Comments are closed.