Flex中如何在mx:Style中用@font-face在Flash SWF中嵌入字体的例子

By Minidxer | October 30, 2008

接下来的例子演示了Flex中如何在mx:Style中用@font-face,在Flash SWF中嵌入字体。

让我们先来看一下Demo可以右键View Source或点击这里察看源代码):


下面是完整代码(或点击这里察看):

Download: main.mxml
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
  3.         layout="vertical"
  4.         verticalAlign="middle"
  5.         backgroundColor="white"
  6.         applicationComplete="init()">
  7.  
  8.     <mx:Script>
  9.         <![CDATA[
  10.             private function init():void {
  11.                 var appInfo:LoaderInfo = Application.application.loaderInfo;
  12.                 /* Just grab the filename from the SWF URL. */
  13.                 var fileName:String = (appInfo.url).split("/").pop();
  14.                 /* Convert bytes to kilobytes. */
  15.                 var kbTotal:String = (appInfo.bytesTotal / 1024).toFixed(2);
  16.                 info.text = fileName + " (" + kbTotal + "kb)";
  17.             }
  18.         ]]>
  19.     </mx:Script>
  20.  
  21.     <mx:Style>
  22.         @font-face{
  23.             src: url('./fonts/fromFlash.swf');
  24.             fontFamily: "Myriad Web Pro";
  25.         }
  26.  
  27.         .myriadWebProFromSWF {
  28.             fontFamily: "Myriad Web Pro";
  29.             fontSize: 24;
  30.         }
  31.     </mx:Style>
  32.  
  33.     <mx:ApplicationControlBar dock="true">
  34.         <mx:Label id="info" />
  35.     </mx:ApplicationControlBar>
  36.  
  37.     <mx:Text styleName="myriadWebProFromSWF">
  38.         <mx:text>The quick brown fox jumped over the lazy dog.</mx:text>
  39.     </mx:Text>
  40.  
  41. </mx:Application>
代码:Peter deHaan 翻译/整理/编译:中文Flex例子

Topics: Font | No Comments » | Tags: , , ,

Search Posts