In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

テキストフィールド入力

テキストフィールドから名前を入力し,それにたいして挨拶をするという,フィールド入力とCHANGEイベント処理の例題
Get Adobe Flash player
by shmdmoto 13 Sep 2010
/**
 * Copyright shmdmoto ( http://wonderfl.net/user/shmdmoto )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/zvIt
 */

package {
    import flash.display.Sprite;
    import flash.text.TextField;
    import flash.text.TextFieldType;
    import flash.events.Event;

    public class TextField_type extends Sprite {
        private var tfResult:TextField;
        private var tfInput:TextField;
        public function TextField_type() {
            tfResult = createTextField(10,70, 200, 20);
            tfInput = createTextField(10,45, 100, 20);
            tfInput.type = TextFieldType.INPUT;
            tfInput.border = true;
            tfInput.text = "";
            tfInput.addEventListener(Event.CHANGE, changeHandler);
        }
        private function changeHandler(e:Event):void {
            tfResult.text = "こんにちは" + tfInput.text + "さん";
        }

        private function createTextField(x:Number, y:Number, width:Number, height:Number):TextField {
            var result:TextField = new TextField();
            result.x = x;
            result.y = y;
            result.width = width;
            result.height = height;
            result.background = true;
            addChild(result);
            return result;
        }
    }
}