• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 220
  • Last Modified:

Is there any way to use Action Script to outline some text ?

I need to create an outline round some text. I know this can be done in the authoring environment by breaking the letters apart and adding an outline to them as shapes (with the ink bottle), but is there any way to do this at runtime on dynamically entered text, or does anyone have good tip for simulating this.

I wrote some actionscript that copies text, recolors it and incrementally moves it n pixels out from the original and down some levels and this creates a passable effect with cursive and non-serif font but it creates quite a jagged effect with serif fonts. I guess something like creating a small circle with my "front" textfield's center as the origin and arranging copies around the circle at lower levels might create a smoother effect but I can't fathom the trig for that at the moment.

This is a tough one and I'm up against it time wise (as always ;) so maximum points.
1 Solution
judefisherAuthor Commented:
I solved this myself and I'll post it here so otherc can benefit. Donate my points to the poor and hungry, please.

The trick is to use a circle, and the drawEllipse function from the Actionscript Cookbook works very nicely as a basis:

In the function below, the radius arguments will control how thick the border is and the x and y arguments need to be the same as the origin of the textField (embedded in an mc in this case but that's not necessary). The more segments you create the smoother the effect is and obviously you need to zero the alpha of the ellipse to hide your guide line and to make the offset textFormat object exactly the same as the format of your original text, except in color or alpha.

I suspect that drop shadow and other effects can be created by making the radius irregular, also.

function drawEllipse(xRadius, yRadius, x, y)
            var ellipse_mc:MovieClip = container_mc.createEmptyMovieClip("ellipse_mc", 1);
            ellipse_mc.lineStyle(0, 0x000000, 100);
              var angleDelta = Math.PI / 24; // Number of segments
              var xCtrlDist = xRadius/Math.cos(angleDelta/2);
             var yCtrlDist = yRadius/Math.cos(angleDelta/2);
             var rx, ry, ax, ay;
              var angle:Number = 0;
              ellipse_mc.moveTo(x + xRadius, y);
              for (var i = 0; i < 48; i++)
                  { // iteration should be twice number of segments
                angle += angleDelta;
                rx = x + Math.cos(angle-(angleDelta/2))*(xCtrlDist);
                ry = y + Math.sin(angle-(angleDelta/2))*(yCtrlDist);
                ax = x + Math.cos(angle)*xRadius;
                ay = y + Math.sin(angle)*yRadius;
                ellipse_mc.curveTo(rx, ry, ax, ay);
            var clipString:String;
            clipString = "offset_" + i + "_mc";
            var offset_mc = container_mc.attachMovie(clip_str, clipString, 0 - i, {_x:rx, _y:ry});
            offset_mc.text_txt.text = text_mc.text_txt.text;
            var offset_fmt:TextFormat = new TextFormat();
            offset_fmt.font = "Arial";//__font_str;
            offset_fmt.size = (__fontHeight);
            offset_fmt.color = 0xFF0000//Number(__textColor_str);
This one is cool !!!!

judefisherAuthor Commented:
Yes, I looked long and hard and never found a solution anywhere else so I'm quite pleased.

Credit must go to Joey Lott, who wrote the Actionscript Cookbook, however - his trig does all the heavy lifting.

You actually get good drop and offset effects by adding color as an argument and then calling the function again with x and y  (not the radius) offset by the amount you want and the color changed.
I might be able to use this bit of code. Thanks for that :)

For plenty more scripts such as this, you should check out the following website. It has a great deal of classes, funtions and prototypes that you can use for all sorts of Flash movies or applications.


But well done on finding this source :)


PAQed, with points refunded (500)

E-E Admin
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now