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

"閉じる"ボタンの注意点

クリックで自分自身を表示リストから外すようなボタンを作る時は、その後フォーカスをstageに戻さないと、
画面をもう一回クリック等するまで、KeyboardEventとかが反応しなくなるというメモ。
Get Adobe Flash player
by o8que 11 Feb 2011
    Embed
/**
 * Copyright o8que ( http://wonderfl.net/user/o8que )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/20dF
 */

package {
    import com.actionscriptbible.Example;
    import com.bit101.components.PushButton;
    import flash.display.Stage;
    import flash.events.KeyboardEvent;
    import flash.events.MouseEvent;
    
    [SWF(width="465",height="465")]
    public class Main extends Example {
        
        public function Main() {
            for (var i:int = 0; i < 5; i++) { 
                createButton(325, 80 * i + 20, false);
                createButton(325, 80 * i + 60, true);
            }
            
            stage.addEventListener(KeyboardEvent.KEY_DOWN, function(event:KeyboardEvent):void {
                trace("Event: KEY_DOWN");
            });
        }
        
        private function createButton(x:Number, y:Number, changesFocus:Boolean):void {
            var button:PushButton = new PushButton(this, x, y, (changesFocus) ? "B" : "A", function(event:MouseEvent):void {
                var stage:Stage = button.stage;
                trace("willTrigger(KeyboardEvent): " + stage.focus.willTrigger(KeyboardEvent.KEY_DOWN));
                button.parent.removeChild(button);
                trace("removeChild(button)");
                if (changesFocus) stage.focus = stage/* or null */;
                trace("willTrigger(KeyboardEvent): " + stage.focus.willTrigger(KeyboardEvent.KEY_DOWN));
            });
        }
    }
}