views:

2005

answers:

2

I am coding in AS3 and want to add a stroke to text that I'm displaying to the screen. My current code is:

format = new TextFormat("BN Elements", 14, 0xEEEEEE, false, false, false, null, null, "left");
format.font = "BN Elements"
scoreText = initText(starsleftText, format, "", 160,5, 545, 61);
scoreText = "Stroke This Text";

As the text is dynamically generated I can't create it as a text object in the Flash IDE - where I know to add a stroke I can use the "glow" function set to 1000% and Low quality.

I suppose my question is, how can I apply the "glow" filter effect with similar properties within AS3 directly? Or is there an alternative "stroke" function I don't know about?

+3  A: 

It's pretty easy:

http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/filters/GlowFilter.html (There's an example at the bottom of the page)

I'm not sure if they've added anything new as far as adding a real stroke, but the glow filter 'stroke' works just as well with code.

You could also create a pixel bender filter that would give you a bit more control over the effect, I can't seem to find any already written ones out there though:(

quoo
oh also, beware, if the text is selectable, using the glow filter will add a stroke to the selection as well.
quoo
A: 

Flash generates its strokes from the edges of shapes. Since you are using text dynamically (not in authoring) Flash can render with either 1) device text which in drawn by the operating system, or 2) embedded text in your SWF file. In the first case, Flash doesn't (currently) have access to the edges to stroke them. In the 2nd, Flash uses a specialized sub-renderer for text that (again currently) doesn't support stroking, or for that matter, anything but solid color fills.

Short answer: stroking of text currently isn't supported in the runtime, although the glow or pixel bender approach suggested is a good idea.

grinliz