Jan Zich
Jan Zich

Reputation: 15323

Multiple fonts in flash.text.TextFormat

Is there a way to set multiple fonts in flash.text.TextFormat similarly as in flash.text.StyleSheet? What I'm trying to do is to have global common TextFormat for all texts in my project, and I would like to make it flexible by providing multiple fonts. I was deciding between flash.text.TextFormat and flash.text.StyleSheet, and in the end I decided to go with flash.text.TextFormat since I don't need any fancy formatting and I don't want to wrap all texts to something like <span class="common">...</span> as flash.text.StyleSheet does not seem to support the * selector (if I'm not mistaken).

Upvotes: 0

Views: 946

Answers (2)

Tyler Egeto
Tyler Egeto

Reputation: 5495

Ya only one font per text format. (You can apply multiple formats to a text field though)

Something I've been playing with in a current project is a static class that defines all my text formats, and a simple interface for retrieving them from else where in my application. I've adopted a HTML like naming convention to help keep them clear. It looks something like this:

public class TextFormats 
{
    public static const NONE:uint = 0;
    public static const H1:uint = 1;
    public static const H2:uint = 2;
    public static const H3:uint = 3;
    public static const P:uint = 4;
    public static const EM:uint = 5;
    public static const ERROR:uint = 6;
    //ect...

    static private var _initialized:Boolean;
    static private var _formats:Object;

    public static function getFormat(type:uint):TextFormat
    {
        if (!_initialized) init();
        return _formats[type] || _formats[NONE];
    }

    static private function init():void
    {
        _formats = { };
        _formats[NONE] = new TextFormat();
        ///ect...

        _initialized = true;
    }
}

I know that's not exactly what your looking for, but it might help or spur an idea.

Upvotes: 0

Josh
Josh

Reputation: 6322

i use stylesheets - i find them much easier to manage. you can even parse an external css stylesheet using the parseCSS function.

you can around the issue of no * selector by wrapping everything in a tag - possibly via a function and then set your default styles to the body tag.

using stylesheets also makes it much easier to style parts of your text by just defining a different style.

hope this helps

Josh

Upvotes: 1

Related Questions