flash on 2009-7-9

by uepon24
♥0 | Line 36 | Modified 2009-07-09 18:58:38 | MIT License
play

ActionScript3 source code

/**
 * Copyright uepon24 ( http://wonderfl.net/user/uepon24 )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/vD2J
 */

package {
	import flash.display.Sprite;
	import flash.events.FocusEvent;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	public class DocumentClass extends Sprite {
		private var debugTF:TextField ;
		public function DocumentClass() {
			//デバッグ用のテキスト
			debugTF = createTextField(600, 20, 0, 0, "はじめにここをクリックしてSWFにフォーカスを移してください。");
			addChild(debugTF);
			//フォーカス検知用テキストフィールド
			var focusTF:TextField = new TextField();
			//ステージ全体を覆うサイズにする
			focusTF.width = stage.stageWidth;
			focusTF.height = stage.stageHeight;
			focusTF.selectable = false;
			focusTF.addEventListener(FocusEvent.FOCUS_IN, onFocusIn);
			focusTF.addEventListener(FocusEvent.FOCUS_OUT, onFocusOut);
			//必ず最上位レイヤーに配置
			addChildAt(focusTF, this.numChildren);
		}
		//ポーズ処理
		private function onFocusOut(e:FocusEvent):void {
			debugTF.text = "SWFからフォーカスが外れたのでポーズ中。灰色のエリアをクリックすると再開します。";
		}
		//再開処理
		private function onFocusIn(e:FocusEvent):void {
			debugTF.text = "SWFにフォーカス中。画面外をクリックするとポーズ状態になります。";
		}
		private function createTextField(w, h, x, y, str):TextField {
			var tf:TextField = new TextField;
			tf.width = w;
			tf.height = h;
			tf.x = x;
			tf.y = y;
			tf.text = str;
			tf.selectable = false;
			return tf;
		}
	}
}