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

キー入力

Get Adobe Flash player
by takishiki 28 Jul 2010
    Embed
/**
 * Copyright takishiki ( http://wonderfl.net/user/takishiki )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/2cxT
 */

package {
    import flash.display.Sprite;
    import flash.events.*;
    import flash.text.TextField;
    import flash.text.TextFieldAutoSize;
    import flash.text.TextFormat;
    
    public class Main extends Sprite {
        public function Main() {
            stage.addEventListener(KeyboardEvent.KEY_UP, keyUp);
        }
        
        private function keyUp(event:KeyboardEvent):void {
            // ↓ここで手抜きをしているので一部のキーの文字がおかしいです。例)「Shift+2」→「@」
            var str:String = String.fromCharCode(event.charCode);
            var my_fmt:TextFormat = new TextFormat();
            var my_txt:TextField = new TextField();
            
            //テキスト
            my_txt.autoSize = TextFieldAutoSize.LEFT;
            my_txt.text = str;
            my_txt.x = stage.stageWidth;
            my_txt.y = Math.round((stage.stageHeight - my_txt.height) * Math.random());
            my_txt.addEventListener(Event.ENTER_FRAME, onEnterFrame);
            
            // テキスト装飾
            my_fmt.size = Math.round(170 * Math.random()) + 30;
            my_fmt.color = Math.round(0xFFFFFF * Math.random());
            my_fmt.bold = true;
            my_txt.setTextFormat(my_fmt);
            
            addChild(my_txt);
            event.updateAfterEvent();
        }
        
     private function onEnterFrame(event:Event):void {
        var target:Object = event.currentTarget;
        target.x = target.x - target.x * 0.05;
        target.alpha = Math.max(target.alpha - 0.02, 0);
        target.width += 10;
        
            // アルファが0になったら削除
        if (target.alpha == 0) {
            target.removeEventListener(Event.ENTER_FRAME, onEnterFrame);
            removeChildAt(0);
        }
        }
    }
}