AS2 + AS3 Draw a Dotted Rounded Corner Box
So you might think that rounded corners is easy in as3 with the new drawing tools. This is only so true if you don't want it dotted.
Thanks to senocular AS2 DashedLine.as which was easily converted to an as3 version DashedLine.as for as3 we can draw dotted lines and curves with actionscript. This left me with the task of using the quadratic drawing tools (no i didnt add a cubic curveTo to the Dashed line class) to draw circles (or quarters of circles, for the curners), which isnt the easiest, but i'll spare you the details and simply say, its done!
Using Draw.curvedBox(obj, offsetX, offsetY, width, height, cornerRadius) we can draw into any graphics object (whether it be a normal Sprite.graphics or a DashedLine Object). This is essential as the Dashed line tool doesnt actually give us a fill, so we might need to draw a normal shape for the background.
-
import com.senocular.drawing.DashedLine
-
import com.tonp.utils.Draw
-
var dl = new DashedLine(this,1,5);
-
dl.lineStyle(3,0x000000,1);
-
Draw.curvedBox(dl,10,10,100,100,20)
to draw a curved corner box with a fill, or solid outline, send in mc.graphics as the first attribute (or just the mc in as2)
So we can now do a box with curved corners in either AS2 or AS3 and in dotted or normal... phew!
Tags: as3 drawing
This entry was posted on Friday, April 25th, 2008 at 2:18 am and is filed under Flash. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
5 comments
-
-
November 18th, 2008 at 7:47 amThis might possibly be exactly what I'm looking for!
Is there a source file or an example uploaded so I can see how this works?
-
November 18th, 2008 at 10:14 amThe source files are in the article, the linked "as" files. For as3 they need to be imported as in the example above and should then work out of the box.
-
January 31st, 2009 at 2:32 amCheers mate that was exactly what I needed but couldn't be bothered to write! Great class.
-
saravana raja
March 27th, 2009 at 5:51 pmHi
Below is the code i tried for testing. but i see nothing working.
pls tell me what i am missing.import com.senocular.drawing.DashedLine;
var shp:Shape = new Shape();
addChild(shp)
var myDashedDrawing:DashedLine = new DashedLine(shp, 10, 5);
myDashedDrawing.moveTo(50, 50);
myDashedDrawing.lineTo(100, 50);
myDashedDrawing.lineTo(100, 100);
myDashedDrawing.lineTo(50, 100);
myDashedDrawing.lineTo(50, 50);