2011-09-24 33 views
1

为了在我的文本框中使用像素字体,我在Flash IDE中创建了一个字体类。然后,我创建了一个TextField实例,其中嵌入了反锯齿的字体设置为位图。我用这些东西出口SWC。AS3:无法输入带有嵌入像素字体的输入TextField

我创建了一个具有良好API的类,可以轻松处理这些东西。

在FDT中,我使用类,这一切正常工作。

这里的问题是我现在想要使用这些文本字段之一作为输入。我尝试将textfield类型设置为TextFieldType.INPUT,但是唯一的做法是允许我选择文本,但不能输入。我还创建了另一个已经设置为输入类型的资产,也不起作用。

我试着用资产,而不是用我的课,然后我可以输入ok。

是否有东西可以防止文本字段在它成为精灵的一部分时被编辑?这里是我的API的代码:

package net.jansensan.as3fflikeui.text 
{ 
    // + ---------------------------------------- 
    //  [ IMPORTS ] 
    // + ---------------------------------------- 

    import flash.display.MovieClip; 
    import flash.display.Sprite; 
    import flash.events.Event; 
    import flash.text.StyleSheet; 
    import flash.text.TextField; 
    import flash.text.TextFieldType; 

    /** 
    * @author Mat Janson Blanchet 
    */ 
    public class BitmapTextfield extends Sprite 
    { 
     // + ---------------------------------------- 
     //  [ CONSTANTS ] 
     // + ---------------------------------------- 

     [Embed(source="../assets/css/ui.css", mimeType="application/octet-stream")] 
     private const CSS :Class; 


     // + ---------------------------------------- 
     //  [ VARIABLES ] 
     // + ---------------------------------------- 

     // display objects 
     private var _textfieldAsset :MovieClip; 
     private var _textfield  :TextField; 
     private var _shadow   :BitmapTextfieldAsset; 

     // private/protected 
     private var _styleSheet :StyleSheet; 


     // + ---------------------------------------- 
     //  [CONSTRUCTOR ] 
     // + ---------------------------------------- 

     public function BitmapTextfield(type:String = TextFieldType.DYNAMIC) 
     { 
      switch(type) 
      { 
       case TextFieldType.DYNAMIC: 
        _textfieldAsset = new BitmapTextfieldAsset(); 
        _textfield = _textfieldAsset.textfieldTXT; 
        _textfield.selectable = false; 
        break; 

       case TextFieldType.INPUT: 
        _textfieldAsset = new BitmapInputTextfieldAsset(); 
        _textfield = _textfieldAsset.textfieldTXT; 
        _textfield.selectable = true; 
        break; 
      } 
      _textfield.htmlText = ""; 

      _shadow = new BitmapTextfieldAsset(); 
      _shadow.textfieldTXT.htmlText = ""; 
      _shadow.x = 1; 
      _shadow.y = 1; 

      _styleSheet = new StyleSheet(); 
      _styleSheet.parseCSS(new CSS()); 
      setStyle(_styleSheet); 

      addChild(_shadow); 
      addChild(_textfieldAsset); 
     } 


     // + ---------------------------------------- 
     //  [ PUBLIC METHODS ] 
     // + ---------------------------------------- 

     public function setWidth(newWidth:int):void 
     { 
      _textfield.width = newWidth; 
      _shadow.textfieldTXT.width = newWidth; 
     } 


     public function setHeight(newHeight:int):void 
     { 
      _textfield.height = newHeight; 
      _shadow.textfieldTXT.height = newHeight; 
     } 


     public function setStyle(newStyle:StyleSheet):void 
     { 
      _styleSheet = newStyle; 
      _textfield.styleSheet = _styleSheet; 
     } 


     public function setText(newText:String):void 
     { 
      _textfield.htmlText = newText; 
      _shadow.textfieldTXT.htmlText = newText; 
     } 


     public function getText():String 
     { 
      return _textfield.text; 
     } 


     public function getHTMLText():String 
     { 
      return _textfield.htmlText; 
     } 


     public function getTextNumLines():uint 
     { 
      return _textfield.numLines; 
     } 


    } 
} 

任何指导将是有用的,在此先感谢!

-mat。

+0

它是否按预期使用非嵌入式字体? – Cameron

回答

2

带样式表的文本字段不可编辑。换句话说,类型属性设置为TextFieldType.INPUT的文本字段将StyleSheet应用于文本字段的默认文本,但内容将不再由用户编辑。考虑使用TextFormat类为输入文本字段分配样式。