2011-03-30 95 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> 

希望这有助于。