Dustin
Dustin

Reputation: 439

Many SWFs, single font embed, without creating textfields through Actionscript?

Is it possible to embed a font in a single SWF to be used throughout many other SWFs, while maintaining the ability to do all the text arrangement and setup through the Flash IDE in those SWFs?

I know I can retrieve a font from an external SWF, register it, and use it in a new TextField. However it would be nice if I didn't have to create every text field in code.

For instance, the following is after loading in a SWF that has a font in it and calling the following using the name of that font:

Font.registerFont();

The original text field will show nothing, while the newly creating one USING THE FORMAT FROM THE ORIGINAL, shows perfectly fine.

        var format:TextFormat = onStageTextField.getTextFormat();

        onStageTextField.embedFonts = true;
        onStageTextField.defaultTextFormat = format;
        onStageTextField.text = "My Text";

        var newTextField:TextField = new TextField();
        newTextField.width = 300;
        newTextField.embedFonts = true;
        newTextField.defaultTextFormat = format;
        newTextField.text = "My Text";
        contentMC.addChild(newTextField);

Upvotes: 1

Views: 158

Answers (1)

case2000
case2000

Reputation: 178

I fear the short answer to your main question is "no." There's ways to embed font with code, and through the IDE, but I don't know of a way to do a hybrid approach like you describe.

An alternative approach:

In your main FLA Create MovieClips holding each style of textfield (or groups of textfields) you want to reuse, style and embed in the IDE. Name the child TextFields something like "txt". Give the MCs linkage ids. Now when you load your child SWF, create & add instances of the MCs for any textfields you need to display using flash.utils.getDefinitionByName(). Update the text in each instance like so: myMC.txt.text = "my text".

The above should work well for dynamic text in lots of fields. When you say "text arrangement"... are you talking about line-break adjustment?

Upvotes: 1

Related Questions