Search Flex Components Free

Custom Search

January 23, 2008

Embedding fonts from a Flash SWF file into a Flex application

The following examples show how you can embed a font from a Flash SWF into a Flex application using @font-face in a <<:Style />> block, or using the [Embed] metadata.




<?xml version="1.0" encoding="utf-8"?>

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"

layout="vertical"

verticalAlign="middle"

backgroundColor="white"

applicationComplete="init()">



<mx:Script>

<![CDATA[

private function init():void {

var appInfo:LoaderInfo = Application.application.loaderInfo;

/* Just grab the filename from the SWF URL. */

var fileName:String = (appInfo.url).split("/").pop();

/* Convert bytes to kilobytes. */

var kbTotal:String = (appInfo.bytesTotal / 1024).toFixed(2);

info.text = fileName + " (" + kbTotal + "kb)";

}

]]>

</mx:Script>



<mx:Style>

@font-face{

src: url('./fonts/fromFlash.swf');

fontFamily: "Myriad Web Pro";

}



.myriadWebProFromSWF {

fontFamily: "Myriad Web Pro";

fontSize: 24;

}

</mx:Style>



<mx:ApplicationControlBar dock="true">

<mx:Label id="info" />

</mx:ApplicationControlBar>

<mx:Text styleName="myriadWebProFromSWF">

<mx:text>The quick brown fox jumped over the lazy dog.</mx:text>

</mx:Text>

</mx:Application>

Related Flex Tutorials