Custom Class for 'Dashed Line' in AS3

Hi all, I am trying to create a custom class for Dashed Line.
I have the attached code in .as file and thr following code in .fla file :

import diagrammingtool.utils.DashedLine;
import flash.geom.Point;
var spt:Point = new Point(200,50);
var ept:Point = new Point(400,100);
var dl:DashedLine = new DashedLine(spt,ept,4,2);

There are no errors but the theres no dashed line appearing either. Can any one point me to the mistake I am making ? Thanks.
package diagrammingtool.utils{
       import flash.geom.Point;
	   import flash.display.Graphics;
	   import flash.display.Sprite;
	   import flash.display.Shape;
        // START CLASS
        public class DashedLine extends Sprite{            
                // CONSTRUCTOR              
               private var startPoint:Point = new Point();
			   private var endPoint:Point = new Point();
               public function DashedLine(sPoint:Point, ePoint:Point, len:Number, gap:Number) {
				   var child:Shape = new Shape();
				   var seglen:Number = len + gap ;
				   var deltax = sPoint.x-ePoint.x; 
				   var deltay = sPoint.y-ePoint.y; 
				   var dist:Number = Math.sqrt(deltax*deltax+deltay*deltay);
				   var noOfSegs:Number =  Math.floor(Math.abs(dist/seglen));
				   var angle:Number = Math.atan2(deltay,deltax);
				   var cx:Number = sPoint.x;
				   var cy:Number = sPoint.y;
				   // add these to cx, cy to get next seg start
				   deltax = Math.cos(angle)*seglen;
				   deltay = Math.sin(angle)*seglen;
				   // loop through each seg
				   for (var n:Number = 0; n < noOfSegs; n++) {,cy);*len,cy+Math.sin(angle)*len);
						cx += deltax;
						cy += deltay;
				   // handle last segment as it is likely to be partial,cy);
				   var delta:Number = Math.sqrt((ePoint.x-cx)*(ePoint.x-cx)+(ePoint.y-cy)*(ePoint.y-cy));
					   // segment ends in the gap, so draw a full dash*len,cy+Math.sin(angle)*len);
				   } else if(delta>0) {
					   // segment is shorter than dash so only draw what is needed*delta,cy+Math.sin(angle)*delta);
				   // move the pen to the end position,ePoint.y);
        // END CLASS

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Antonio EstradaTech Leader / Senior Web DeveloperCommented:
Here's an old AS2 class I ported to AS3 also a while back. It works fine, so you might as well check it out:


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
whatisittellmeAuthor Commented:
Thank you. I tried using the one you sent with the following code on the .fla file. I might be doing something wrong, the dashed line doesnt show up :(

var dl = new DashedLine(000000,4,90,200,300,400,500,10,5);

Open in new window

whatisittellmeAuthor Commented:
oops, my works. the had given the coordinates that were way off the stage. figured out. thanks !
Antonio EstradaTech Leader / Senior Web DeveloperCommented:
Glad to help!

whatisittellmeAuthor Commented:
Hi 'Vulturous'. Could you take a look at this question:

I have a similar problem but in this case I want to implement so that it can be overlayed on google map/microsoft live maps using UMap(it is an Advanced Flash Component available for free download). I would greatly appreciate any help. Thanks !
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Adobe Flash

From novice to tech pro — start learning today.