flex 字体加载方式1

 flex加载嵌入式字体:

 1 先把ttf字体打包为swf字体

  package

{
	import flash.display.Sprite;
	
	public class FontAssets extends Sprite
	{
		 [Embed(source="font/AlphaFitness.ttf",fontName="zhzFont1",mimeType="application/x-font")]
		 public var pixelFont1:Class;
		 
		 [Embed(source="font/WeibeiFont.ttf",fontName="zhzFont2",mimeType="application/x-font")]
		 public var pixelFont2:Class;
		 
		 [Embed(source="font/WindTailsFont.ttf",fontName="zhzFont3",mimeType="application/x-font")]
		 public var pixelFont3:Class;
		 
		 [Embed(source="font/YayaSimplifiedFont.ttf",fontName="zhzFont4",mimeType="application/x-font")]
		 public var pixelFont4:Class;
		 
		 [Embed(source="font/YegenyouSimplifiedFont.ttf",fontName="zhzFont5",mimeType="application/x-font")]
		 public var pixelFont5:Class;
	}
}

 fontName:字体名,调用的时候用的着

pixelFont1:生成的字体类,调用的时候用的着

用flex builder生成swf文件,FontAssets.swf

 

编写测试类:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" minWidth="955" minHeight="600" creationComplete="initApp(event)">
	<mx:Script>
		<![CDATA[
			import mx.events.FlexEvent;
			private function fontLoadComplete(e:Event):void
			{
				Font.registerFont(e.target.content["pixelFont1"]);
				txt1.setStyle("fontFamily","zhzFont1");
			}

			protected function initApp(event:FlexEvent):void
			{
				// TODO Auto-generated method stub
				loader.source="FontAssets.swf";
				loader.load();
			}

		]]>
	</mx:Script>
	<mx:SWFLoader id="loader"  complete="fontLoadComplete(event)"/>
	<mx:ProgressBar id="loadBar" source="loader" x="100" y="400" toolTip="加载了:{loadBar.percentComplete}%"/>
	<mx:VBox>
		<mx:Text id="txt1" text="test words" fontSize="50"/>
		<mx:Text id="txt2" text="test words" fontSize="12"/>
	</mx:VBox>
</mx:Application>
   红色的部分是你在生成嵌入式字体时用到的。。。先在系统注册swf字体,然后 txt1.setStyle("fontFamily","zhzFont1"); 调用。。。。


flex 字体加载方式1_第1张图片

 

 

你可能感兴趣的:(xml,Flex,Flash,嵌入式,Adobe)