【问题标题】:AS3: Cannot type in an input TextField with an embedded pixel fontAS3:无法输入嵌入像素字体的输入文本字段
【发布时间】:2011-11-24 02:26:43
【问题描述】:

为了在我的文本字段中使用像素字体,我在 Flash IDE 中创建了一个字体类。然后,我创建了一个 TextField 实例,其中嵌入了抗锯齿设置为位图的字体。我用所有这些东西导出了一个 SWC。

我创建了一个具有良好 API 的类,以便能够轻松处理这些内容。

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

这里的问题是我现在想使用这些文本字段之一作为输入。我尝试将文本字段类型设置为 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;
        }


    }
}

任何指导都会很有用,在此先感谢!

-垫子。

【问题讨论】:

  • 使用非嵌入字体是否能按预期工作?

标签: actionscript-3 embed pixel-fonts


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-04-11
    • 2012-10-10
    • 2021-10-17
    相关资源
    最近更新 更多