Skip navigation
Thorjelly
Currently Being Moderated

Create font assets with unique fontName in Flash Professional?

Feb 12, 2013 3:23 AM

Tags: #flash_professional #external_stylesheet #stylesheet #embedding_fonts #font_family

Hello,

 

Right now if I create a Font object in Flash Professional and export it for actionscript, when I create a new instance of this font in actionscript, its fontName property is the original font that I had embedded.

 

For example, if the library symbol for the font's name is ApplicationFontRegular, and the class name exported in Flash Professional is also ApplicationFontRegular, its fontName property is still Century Gothic if the font I use is Century Gothic. This means that I must use the font name property Century Gothic in any css file I want to use.

 

But if I change what the embedded font is, I have to change all my css files too, so it uses the correct embedded font.

 

I want to know if there is any way to give an embedded font a unique fontName property which can be used in a css file regardless of what font was originally embedded.

 

The real problem is, if I load in a .swf at runtime that just contains my font assets and register the font at runtime, I'd like it to work with my css files regardless of what .swf file I actually load in, if multiple .swf files embed different fonts. So one file could have embedded Century Gothic, another embed Arial, but they both share a fontName such as ApplicationFont so that they both can use the same css files which use the font name property ApplicationFont. And it'd also be great if I could tell TextFields made in Flash Professional to use a font by this fontName too, so art assets made in Flash Professional also don't care about what original font had been embedded and registered at runtime.

 

Is there any way to do this? This would be extremely useful to me.

 

Thanks,

Erik

 
Replies
  • Currently Being Moderated
    Feb 12, 2013 4:09 AM   in reply to Thorjelly

    Could you show how you use css files to load your assets?

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 12, 2013 5:03 AM   in reply to Thorjelly

    I`m a little confused, I admit. In your 1st Post you talk about your Problem with css files

     

    This means that I must use the font name property Century Gothic in any css file I want to use.

     

    But if I change what the embedded font is, I have to change all my css files too, so it uses the correct embedded font.

     

    I want to know if there is any way to give an embedded font a unique fontName property which can be used in a css file regardless of what font was originally embedded.

    Then in your next post you state:

     

    The .css files right now are embedded in the application.

    In which application? The Flash application? Are you using a cms? Other webtechnologies like php? MySQL?

    How Are they embedded (included like in a php file, plain text?)

    Don`t get me wrong, I have a vague idea how to actually help you, but at this moment your problem is not really clear to me.

     

    After some research I have an idea what you are hinting at: You are using this class to parse css files that you use inside your flash file to style Textfields applicationwide. And you want the font-family property to have a generic name that can be linked to different font assets? Is that correct?

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 12, 2013 5:34 AM   in reply to Thorjelly

    The flash.utils class could be helpful.

     

    if you load an Arial.swf that contains an exported Arial Characterset with Linkage "GenericFontName".

     

    you would set up your Textfields like:

     

    var embeddedFont:Font = new GenericFontName();

    var textFormat:TextFormat = new TextFormat();

    textFormat.font = embeddedFont.fontName;

     

    var textField:TextField= newTextField();

    textField.setStyle("textFormat", textFormat);

    textField.setStyle("embedFonts",true);

    textField.text  = "The quick brown fox jumps over the lazy dog.";

     

    trace("getQualifiedClassName(embeddedFont)"+getQualifiedClassName(embe ddedFont));

    //result is "GenericFontName"

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 12, 2013 8:12 AM   in reply to Thorjelly

    The Problem with Font is essentially that you have no setters. This was intended by Adobe, I don`t know why. Maybe legal restrictions.

    From the original comments:

     

    /**

         * The Font class is used to manage embedded fonts in SWF files. Embedded fonts

         * are represented as a subclass of the Font class. The Font class is currently useful only to

         * find out information about embedded fonts; you cannot alter a font by

         * using this class.

         *

         *   You cannot use the Font class to load external fonts, or to create an instance

         * of a Font object by itself. Use the Font class as an abstract base class.

         * @langversion    3.0

         * @playerversion    Flash 9

         * @playerversion    Lite 4

         */

     

    Now all you have to do is to make you a new dynamic property, that you can set yourself:

     

    //SpecialFont.as

     

    package

    {

     

        import flash.text.Font;

     

        public class SpecialFont extends Font

        {

     

            private var alias:String;

     

            public function SpecialFont()

            {

                // constructor code

            }

     

            public function setAlias(_alias:String):void

            {

                this.alias = _alias;

            }

            public function getAlias():String

            {

                return alias;

            }

        }

    }

     

    //Link the class to your compiler or simply put in a directory with your other class files

     

    Then in you main.fla use sth. like:

     

    var embeddedFont:SpecialFont = new GenericFontName();

    embeddedFont.setAlias("Superfont");

     

    trace("embeddedFont.fontName:"+embeddedFont.fontName);

    //will trace the original fontname

    trace("embeddedFont.getAlias():"+embeddedFont.getAlias());

    //will get the Alias you set earlier

    //you have now a dynamic property you can set yourself

     

    important: you have now to change every base class in your LibraryFontassets from flash.text.font to SpecialFont

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 12, 2013 9:46 AM   in reply to moccamaximum

    I don't think that will work, because the CSS code doesn't care about your getAlias() function.

     

    However, you might be on to something, because a read-only property just about has to be a getter under the hood. If Adobe hasn't marked it final, you should be able to do something like

     

    override public function get fontName():String {

       return _alias;

    }

     

    If it is final, possibly you could approach it from the StyleSheet side and override the parsing method to look at some custom property.

     
    |
    Mark as:
  • Currently Being Moderated
    Feb 13, 2013 12:43 AM   in reply to Thorjelly

    This thread has some interesting workarounds

     
    |
    Mark as:

More Like This

  • Retrieving data ...

Bookmarked By (0)

Answers + Points = Status

  • 10 points awarded for Correct Answers
  • 5 points awarded for Helpful Answers
  • 10,000+ points
  • 1,001-10,000 points
  • 501-1,000 points
  • 5-500 points