Link to home
Start Free TrialLog in
Avatar of judefisher
judefisher

asked on

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.
Avatar of judefisher
judefisher

ASKER

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);
            offset_mc.text_txt.setTextFormat(offset_fmt);
            }
      }
This one is cool !!!!

-kp
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.

http://proto.layer51.com/

But well done on finding this source :)

Cheers

-OBCT
ASKER CERTIFIED SOLUTION
Avatar of Computer101
Computer101
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial