{"id":5,"date":"2008-05-30T16:16:22","date_gmt":"2008-05-30T22:16:22","guid":{"rendered":"http:\/\/www.cartogrammar.com\/blog\/?p=5"},"modified":"2009-08-19T08:48:45","modified_gmt":"2009-08-19T13:48:45","slug":"drawing-dashed-lines-with-actionscript-3","status":"publish","type":"post","link":"https:\/\/andywoodruff.com\/blog\/drawing-dashed-lines-with-actionscript-3\/","title":{"rendered":"Drawing dashed lines with ActionScript 3"},"content":{"rendered":"<p>Drawing in Flash dynamically with ActionScript is a jolly fun time, but when doing so one of course lacks some of the finer controls of drawing the graphics manually in the Flash authoring environment.  One such deficiency is dashed lines, so a while back I made a simple DashedLine class in AS3 to use here and there in my projects.<\/p>\n<p>It&#8217;s basically a Sprite that has simple drawing methods with dashed lines. Just make a new instance, providing the line width, color, and an array of alternating dash and gap lengths (in pixels).  Then call <code>moveTo()<\/code> and <code>lineTo()<\/code> methods directly on the Sprite, not its <code>graphics<\/code> property.  (You can also do <code>beginFill()<\/code> if you want.) For example:<\/p>\n<div class=\"codeblock\">\n<p><img decoding=\"async\" src=\"http:\/\/www.cartogrammar.com\/images\/dashedLine.jpg\" alt=\"Dashed line triangle\" \/><\/p>\n<p><code>var dashy:DashedLine = new DashedLine(1,0x339933,new Array(8,4,2,4));<br \/>\ndashy.moveTo(0,50);<br \/>\ndashy.lineTo(100,0);<br \/>\ndashy.lineTo(200,50);<br \/>\ndashy.lineTo(300,0);<br \/>\naddChild(dashy);<br \/>\n<\/code><\/p>\n<\/div>\n<p style=\"text-align:center;\">Try it out below!<\/p>\n\n<object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\"\n\t\t\tid=\"fm_dashTest_1876197432\"\n\t\t\tclass=\"flashmovie\"\n\t\t\twidth=\"400\"\n\t\t\theight=\"200\">\n\t<param name=\"movie\" value=\"http:\/\/www.cartogrammar.com\/flash\/dashTest.swf\" \/>\n\t<!--[if !IE]>-->\n\t<object\ttype=\"application\/x-shockwave-flash\"\n\t\t\tdata=\"http:\/\/www.cartogrammar.com\/flash\/dashTest.swf\"\n\t\t\tname=\"fm_dashTest_1876197432\"\n\t\t\twidth=\"400\"\n\t\t\theight=\"200\">\n\t<!--<![endif]-->\n\t\t\n\t<!--[if !IE]>-->\n\t<\/object>\n\t<!--<![endif]-->\n<\/object>\n<p>This is by no means complete, as I'd like to add the rest of the usual drawing methods (curves are going to be tricky) and resolve the bugs that surely exist.\u00a0 For now, though, download the <a href=\"http:\/\/www.cartogrammar.com\/source\/DashedLine.as\">DashedLine class<\/a> as is; hopefully it'll make sense through the basic comments I've included.<\/p>\n<p><a href=\"http:\/\/www.cartogrammar.com\/source\/DashedLine.as\">DashedLine.as<\/a><br \/>\n<a href=\"http:\/\/www.cartogrammar.com\/source\/dashTest.zip\">dashTest.zip<\/a> (AS file plus the above demo FLA)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Drawing in Flash dynamically with ActionScript is a jolly fun time, but when doing so one of course lacks some of the finer controls of drawing the graphics manually in the Flash authoring environment. One such deficiency is dashed lines, so a while back I made a simple DashedLine class in AS3 to use here [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[6],"tags":[14,9],"class_list":["post-5","post","type-post","status-publish","format-standard","hentry","category-code","tag-as3","tag-drawing"],"_links":{"self":[{"href":"https:\/\/andywoodruff.com\/blog\/wp-json\/wp\/v2\/posts\/5","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/andywoodruff.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/andywoodruff.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/andywoodruff.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/andywoodruff.com\/blog\/wp-json\/wp\/v2\/comments?post=5"}],"version-history":[{"count":1,"href":"https:\/\/andywoodruff.com\/blog\/wp-json\/wp\/v2\/posts\/5\/revisions"}],"predecessor-version":[{"id":347,"href":"https:\/\/andywoodruff.com\/blog\/wp-json\/wp\/v2\/posts\/5\/revisions\/347"}],"wp:attachment":[{"href":"https:\/\/andywoodruff.com\/blog\/wp-json\/wp\/v2\/media?parent=5"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/andywoodruff.com\/blog\/wp-json\/wp\/v2\/categories?post=5"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/andywoodruff.com\/blog\/wp-json\/wp\/v2\/tags?post=5"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}