2011-03-30 93 views
1

ActionScript類當創建一個MXML組件很容易嵌入這種方式所需的字體:嵌入字體中的Flex

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

在我的代碼,我需要嵌入字體爲是部分的組件在* .as文件中實現的類。我怎樣才能做到這一點?

問候,拉法爾

回答

3

我在我的網站覆蓋這幾個星期前。有太多的信息要複製/粘貼在這裏,所以你可以得到它:http://divillysausages.com/blog/as3_font_embedding_masterclass

還有代碼&源文件以及。如果您有任何問題,請告訴我。

+0

好的。但是如何將TextFormat對象應用於包含Text對象的VBox? – rafalry 2011-03-30 11:01:05

+0

你能不能直接在Text對象上設置字體屬性,flex會選中它? (在文本對象上稍微旋轉一下,看它是否嵌入)。您還可以嘗試Text對象上的樣式:http://help.adobe.com/zh_CN/FlashPlatform/reference/actionscript/3/mx/controls/Text.html#commonStyleSummary – divillysausages 2011-03-30 12:50:00

+0

此外,還有用於嵌入字體的幫助文件在flex 4中:http://help.adobe.com/zh_CN/flex/using/WS2db454920e96a9e51e63e3d11c0bf69084-7f5f.html#WS02f7d8d4857b1677-11e364d1266679ac18-8000 - 它充滿了有用的信息 – divillysausages 2011-03-30 12:50:53

0

這裏是簡單的示例如何可以在自定義ActionScript部件嵌入字體:爲簡單起見

package 
{ 
import flash.display.DisplayObject; 

import mx.core.IUITextField; 
import mx.core.UIComponent; 
import mx.core.UITextField; 

[Style(name="fontFamily", type="String", inherit="yes")] 
public class ComponentWithFontEmbedding extends UIComponent 
{ 
    private var label:IUITextField; 

    override protected function createChildren():void 
    { 
     super.createChildren(); 

     if (!label) 
     { 
      label = IUITextField(createInFontContext(UITextField)); 
      label.styleName = this; 
      addChild(DisplayObject(label)); 
      label.text = "Hello"; 
     } 
    } 

    override protected function measure():void 
    { 
     measuredWidth = measuredMinWidth = 100; 
     measuredHeight = measuredMinHeight = 50; 
    } 
} 
} 

予省略實際的測量。所以代碼非常簡單,並使用非常輕量級的UITextField。但是你可以使用類似的方式使用樣式。

樣品用法如下:

<?xml version="1.0" encoding="utf-8"?> 
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" minWidth="955" minHeight="600" xmlns:local="*"> 
    <mx:Style> 
     @font-face { 
      src: local("Arial"); 
      fontFamily: ArialEmbedded; 
     } 
    </mx:Style> 
    <local:ComponentWithFontEmbedding fontFamily="ArialEmbedded" verticalCenter="0" horizontalCenter="0" /> 
</mx:Application> 

希望這有助於。