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!
November 9th, 2007 at 1:17 am
Thanks this is just what I needed.
April 18th, 2008 at 1:31 pm
Thank you for this nice work. I will use it in the coming version of my site, I’ll show the result ^___^
April 23rd, 2008 at 12:37 pm
Nice one, many thanks!
I noticed something when testing it though. If you, for example, have an onenterframe that clears the line and draws a new line each frame, the line will “animate” (similar to the marquee tool in photoshop), since the dash offset isn’t reset. This change to the clear-method seems to have done the trick for me:
public function clear():void {
this.isLine = true;
this.overflow = 0;
this.pen = {x:0, y:0};
this.target.clear();
}
(I have only tested that together with moveTo and lineTo though, don’t know if it will break some of the other methods in there.)
August 9th, 2008 at 5:20 pm
Honi soit legate left buy cytotec then announced estivities.
August 23rd, 2008 at 3:13 am
THis does not work for me at all
import dashedline;
import flash.display.Shape;
var n= new Shape()
var dashLines:dashedline = new dashedline(this, 10, 6);
dashLines.lineStyle(10,0×0000FF,50)
dashLines.moveTo(50, 50);
dashLines.lineTo(100, 50);
September 17th, 2008 at 3:23 pm
You need to add your shape n to the display list
eg. addChild(n);
October 20th, 2008 at 8:06 pm
Hey thanks! The only thing that is missing is the how to on the Draw class.
October 25th, 2008 at 12:55 am
Good for people to know.
October 27th, 2008 at 5:24 am
[…] http://blog.alegitimatebusiness.com/2007/11/07/as2-as3-draw-a-dotted-rounded-corner-box/ « ???????????????????? […]
February 5th, 2009 at 8:50 pm
[…] 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. […]
March 27th, 2009 at 10:19 pm
Hey, the senocular site is down and I need this dashed curve library for AS2. Does any one have it by any chance? Thanks
Joe
April 24th, 2009 at 10:58 am
I read your blog for a long time and must tell you that your posts are always valuable to readers.
May 26th, 2009 at 12:53 pm
Really nice work, thanks man !
Using Flashdevelop however, i get all these ‘warnings’ for all sorts of variables not having a type-declaration, how would you go about that ? Should i just add them or leave strictMode ? Or ignore ? (although that doesn’t really add to the workflow)
I was just wondering, I will declare them in my copy..
July 22nd, 2009 at 4:20 pm
I’ve got a few layers in my .fla file and the line (”dl”) is being drawn on the stage in the bottom-most layer only. In other words, if I put any kind of display object on the stage it’s covering up the line.
Is there a way to add the dashedline object to another movie clip? As it is, I’m getting the following error:
TypeError: Error #1034: Type Coercion failed: cannot convert com.senocular.drawing::DashedLine@417cd151 to flash.display.DisplayObject.
Thanks for great class.
July 23rd, 2009 at 2:42 am
The DashedLine class takes a target which is draws into the .graphics of. You seem to be trying to addChild on the DashedLine object, not the clip which it is drawing the graphics into.
DashedLine isnt a display object, it just draws into your displayobject - which you should change the level of - via adding it to your other clip
September 3rd, 2009 at 11:11 pm
Excellent site, keep up the good work
December 14th, 2009 at 9:31 pm
Hi … I found your website by mistake. I was searching in Yahoo for PDF software that I had already bought when I came upon your site, I must say your website is pretty cool I just love the theme, its amazing!. I don’t have the time at the moment to fully read your entire site but I have bookmarked it and also will sign up for your RSS feed. I will be back in a day or two. thanks for a awesome site.
December 18th, 2009 at 9:24 am
???????? ??? ??????! ? ??? ????? ?? ??? ???? ????? ? ???????? ????? ???!
February 24th, 2010 at 3:41 pm
Duuuuuuuuude.. Needed a curved dashed line drawer for AS3.. Did some googling around and looksy who’s name popped up.. Worked a treat.. Thanks Polly.. I knew you were good for something (apart from chugging jugs of beer)
March 10th, 2010 at 3:07 pm
Thanks to you and senocular for the great Dashed line class. And thank you, fiskhandlarn for the clear () code, it’s exactly what I needed.
March 13th, 2010 at 7:30 am
This site I found has lots of great info on herbs and was really helpful. Its hard to find a good place with good information
March 25th, 2010 at 12:55 am
yo good website yea nice job good good…this post deserves nothing …hahaha just joking
…nice post
ohhh nice info
April 12th, 2010 at 4:22 pm
I’m a big fan of this site and I check it regularly. Keep up the great work!
April 19th, 2010 at 7:37 am
Hey, I read all your articles, keep them coming.
April 25th, 2010 at 1:59 pm
I really appreciate the work that you put into your blog. It really shows. Thanks
June 6th, 2010 at 9:42 am
I’ve been really enjoying Treme. I’ve missed the Wire.