Groups | Blog | Home
all groups > flash actionscript > may 2006 >

flash actionscript : Format ALL text fields?


Miriam McD
5/19/2006 7:45:54 PM
Hi -

I've searched everywhere and can't find an answer to this, so any help would
be appreciated. I have a movie with multiple dynamic text fields. These text
fields are drawn into the movie at certain frames (not created using AS). The
text is being dynamically created using flashVars.

I have a global audience and would like to dynamically embed fonts depending
on the country. So, into the flashVars section of my HTML, I have:

font=Embed

or

font=noEmbed

(depending on which country that HTML file will be delivered to)

So, I'm using _sans as the default font on the textFields (set in the property
inspector). I've got code in the first frame of my movie:

onEnterFrame = function (success) {
if (_root.font == "Embed") {
textMC.text.setTextFormat(embedFormat);
textMC.text.embedFonts = true;
}
}

var embedFormat:TextFormat = new TextFormat();
embedFormat.font = "LuzSans-Medium";

This is working great for a single text field. However, I'd like to be able to
set this text format for ALL text fields in my movie, rather than having to set
each text field separately. Is there a way to do this? By the way, because of
my target audience, I need to publish to Flash Player 6, so I don't think I can
use CSS.

Any ideas?

Thanks!

Miriam
blemmo
5/20/2006 12:00:00 AM
Hi,

I didn't try to see if it really works, but maybe it's possible to use the
prototype property to achieve this:
if (_root.font == "Embed") {
TextField.prototype.setTextFormat(embedFormat);
TextField.prototype.embedFonts = true;
}
}
This should affect all TextFields in the movie (if it affects anything...).

Don't use onEnterFrame for this; the name is misleading: it executes
repeatedly with the speed of the frame rate, so it's more like onFrameChange
(but it also executes repeatedly if there's just 1 frame in the movie).
So it would execute the code every X ms, depending on the frame rate. If you
assign the code to frame 1, without onEnterFrame, it will execute when the
playhead is on that frame, only once if the movie isn't looped. That's enough
in this case.

hth,
blemmo
NSurveyor
5/20/2006 1:07:11 PM
Miriam McD
5/21/2006 1:15:34 AM
Thank you both for your responses. Unfortunately, the prototype property didn't
work. So, I'm still looking for suggestions...

As far as onEnterFrame goes... I didn't think I would need it either, but my
original code doesn't work without it.

Miriam
AddThis Social Bookmark Button