09
Oct
07

Embedding fonts by name instead of location

The following example shows how you can embed a font in Flex by specifying the font name instead of a location by using the local() function instead of the src() function when embedding a font.

Full code after the jump.

View MXML

<?xml version="1.0" encoding="utf-8"?>
<!-- http://blog.flexexamples.com/2007/10/09/embedding-fonts-by-name-instead-of-location/ -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
        layout="vertical"
        verticalAlign="middle"
        backgroundColor="white"
        applicationComplete="init();">

    <mx:Style>
        @font-face {
            src:local("Arial");
            fontFamily: ArialEmbedded;
        }

        @font-face {
            src:local("Arial");
            fontFamily: ArialEmbedded;
            fontWeight: bold;
        }
    </mx:Style>

    <mx:Script>
        <![CDATA[
            private var bTotal:Number;

            private function init():void {
                bTotal = Application.application.loaderInfo.bytesTotal;
                /* Convert from bytes to kilobytes. */
                lbl.text = (bTotal / 1024).toFixed(2) + " KB";
            }
        ]]>
    </mx:Script>

    <mx:ApplicationControlBar dock="true">
        <mx:Label id="lbl" />
    </mx:ApplicationControlBar>

    <mx:ProgressBar id="progressBar"
            label="Loading Flex Application"
            labelPlacement="center"
            fontFamily="ArialEmbedded"
            rotation="15"
            indeterminate="true"
            themeColor="haloSilver" />

</mx:Application>

View source is enabled in the following example.

For more information on embedding fonts in Flex, see “Locating embedded fonts” in the Flex documentation.


1 Response to “Embedding fonts by name instead of location”


  1. 1 dormouse Oct 9th, 2007 at 6:33 pm

    Very Well, use this:
    @font-face {
    src:local(”Arial”);
    fontFamily: ArialEmbedded;
    fontWeight: bold;
    }
    Is the compiled swf binding the Arial font or not?

Leave a Reply

This blog is terrible at eating HTML tags. If you plan on posting code/XML, please escape your "<" characters as "&lt;" and your ">" characters as "&gt;".




Badge Farm

  • Firefox 2
  • Powered by Redoable 1.2
  • Feeds burnt by Feedburner
  • Feed