AS3 – Loading CSS and Fonts


Working with CSS and fonts in Flash (especially with dynamic text) can be a huge pain. I have come up with a way that makes it a lot easier. What I do is load them up, store a reference to the css file in a global class, and simply refer to that class when you need to use the fonts and css. The css styles dictate which fonts are used where within your application.

This method seems to work out well and saves on file size as you are referring to an instance of the font instead of instantiating it over and over again etc. (You will need the FontLoader class in order for this to work.)

Description of the files after the jump…

Description of the files in the zip:

  • LoadCSSAndFontsExample.fla – the file that will use the loaded fonts and css
  • LoadCSSAndFontsExample.as – Document Class for the above fla
  • fonts.fla – File that you will embed your fonts in that you want to use
  • LoadCSSAndFonts.as – AS class that loads the css and fonts swf file
  • GlobalVariables.as – AS class that will store your css file and allow you to reference it later without needing to create a new instance each time
  • Again, you will need to download FontLoader from the link above…

    My method borrowed a lot from this post over at The Tech Labs.

    Fonts used are from dafont:

  • http://www.dafont.com/posca-mad-thrasherz.font
  • http://www.dafont.com/chopin-script.font
  •   LoadCSSAndFonts (290.6 KiB, 47 hits)

    Spread the Good Word:
    • Digg
    • del.icio.us
    • Facebook
    • NewsVine
    • StumbleUpon

    , , , ,

    1. No comments yet.
    (will not be published)