Flex中通过fontFamily和fontWeight样式在LinkButton控件中使用嵌入字体的例子

By Minidxer | September 5, 2008

接下来的例子演示了Flex中如何通过fontFamily和fontWeight样式,在LinkButton控件中使用嵌入字体。

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


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

Download: main.mxml
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <mx:Application name="LinkButton_fontFamily_test"
  3.         xmlns:mx="http://www.adobe.com/2006/mxml"
  4.         layout="vertical"
  5.         verticalAlign="middle"
  6.         backgroundColor="white">
  7.  
  8.     <mx:Style>
  9.         @font-face {
  10.             src: local("Arial");
  11.             fontFamily: ArialEmbedded;
  12.             fontWeight: bold;
  13.         }
  14.  
  15.         LinkButton {
  16.             fontFamily: ArialEmbedded;
  17.         }
  18.     </mx:Style>
  19.  
  20.     <mx:LinkButton id="linkButton"
  21.             label="LinkButton"
  22.             rotation="45" />
  23.  
  24. </mx:Application>

下面是相同功能的ActionScript实现代码:

Download: main.mxml
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <mx:Application name="LinkButton_fontFamily_test"
  3.         xmlns:mx="http://www.adobe.com/2006/mxml"
  4.         layout="vertical"
  5.         verticalAlign="middle"
  6.         backgroundColor="white"
  7.         initialize="init();">
  8.  
  9.     <mx:Script>
  10.         <![CDATA[
  11.             import mx.controls.LinkButton;
  12.  
  13.             [Embed(systemFont="Arial",
  14.                     fontName="ArialEmbedded",
  15.                     fontWeight="bold",
  16.                     mimeType="application/x-font")]
  17.             private const arialEmbedded:Class;
  18.  
  19.             private var linkButton:LinkButton;
  20.  
  21.             private function init():void {
  22.                 linkButton = new LinkButton();
  23.                 linkButton.label = "LinkButton";
  24.                 linkButton.rotation = 45;
  25.                 linkButton.setStyle("fontFamily", "ArialEmbedded");
  26.                 addChild(linkButton);
  27.             }
  28.         ]]>
  29.     </mx:Script>
  30.  
  31. </mx:Application>
代码:Peter deHaan 翻译/整理/编译:中文Flex例子

Topics: Flex | No Comments » | 77 views Tags: , ,

Related Post

Leave a Comment

Name(*):

E-Mail(*) :

Website :

Comments :

Search Posts

赞助商链接

Archives