1

テキストフィールドでピクセル フォントを使用するために、Flash IDE でフォント クラスを作成しました。次に、アンチエイリアシングをビットマップに設定してフォントを埋め込んだ TextField インスタンスを作成しました。これらすべてを含む SWC をエクスポートします。

このようなことを簡単に処理できるように、素敵な API を備えたクラスを作成しました。

FDT では、クラスを使用していますが、これはすべて適切に機能します。

ここでの問題は、これらのテキストフィールドの 1 つを入力として使用したいということです。テキストフィールドのタイプを 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;
        }


    }
}

事前に感謝します。

-マット。

4

1 に答える 1

2

A text field with a style sheet is not editable. In other words, a text field with the type property set to TextFieldType.INPUT applies the StyleSheet to the default text for the text field, but the content will no longer be editable by the user. Consider using the TextFormat class to assign styles to input text fields.

于 2012-03-07T22:49:44.490 に答える