DashedLine and DashedPolyLine extending Degrafa

Posted on June 16, 2008 | Comments Off

I needed to draw some dashed lines and polylines for something I was working on. I was already using Degrafa and wanted to create the dashed lines by extending Degrafa. It was actually easier then I thought it would be.

You can see the finished result here and the view source code is enabled through right clicking. The two new classes DashedLine and DashedPolyline extend Line and Polyline and added two new properties “dash” and “gap”. You set these two values with the value of how big you want the dash and the gap to be. In the future this could be extended to have any number of dash/gap patterns but all I needed was a simple repeating one.

This was based on the Degrafa 1.2 swc but it should work for the 2.2* latest drops.

All the extending that was needed was to inherit the Line and Polyline class and override the preDraw() method. In the overridden preDraw() method I looped through the normal x,y cords and create extra commands based on the dash and gap properties that I exposed in the two new classes DashedLine and DashedPolyline.

NOTE: I did find the use of private member variables and methods in Line and Polyline to be restrictive and had to call super.preDraw() first to make sure some things where called. It still worked for my case but if you wanted to do something total different it was impossible to set the _setBounds correctly.