Testing Mouse Event for Safari

by Fumio
Safari fails to catch MouseEvent.MOUSE_UP outside the stage.   After the pointer is moved outside the stage with the mouse button pressed then the button is released outside the stage, Safari seems to give up watching the mouse.

Safariではステージ外のMouseEvent.MOUSE_UPイベントが受取れない。マウスボタンを押したままポインタをステージ外に出すして放すと、マウスイベントを見なくなるようだ。
♥0 | Line 53 | Modified 2011-12-31 14:32:56 | MIT License
play

ActionScript3 source code

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

package  {
	import flash.display.Sprite;
	import flash.display.Graphics;
	import flash.display.Stage;
	// import flash.display.StageScaleMode;
	// import flash.display.StageAlign;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	import flash.text.TextFieldAutoSize;
	import flash.text.TextFormat;
	import flash.text.TextFormatAlign;
	// [SWF(width = "240",height = "180")]
	public class MouseUpTest extends Sprite {
		private var my_txt:TextField = new TextField();
		private var label_txt:TextField = new TextField();
		private var my_fmt:TextFormat = new TextFormat();
		private var bMouseDown:Boolean = false;
		public function MouseUpTest() {
			// stage.scaleMode = StageScaleMode.NO_SCALE;
			// stage.align = StageAlign.TOP_LEFT;
			// Creating a TextField for display
			createTextField();
			drawOutline();
			setMouseListeners();
		}
		private function setMouseListeners():void {
			var _stage:Stage = stage;
			_stage.addEventListener(MouseEvent.MOUSE_DOWN, mouseEventHandler);
			_stage.addEventListener(MouseEvent.MOUSE_UP, mouseEventHandler);
			_stage.addEventListener(Event.MOUSE_LEAVE, mouseEventHandler);
			_stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMoveHandler);
		}
		private function mouseEventHandler(eventObject:Event):void {
			xTrace(eventObject.type);
		}
		private function mouseMoveHandler(eventObject:MouseEvent):void {
			var bDown:Boolean = eventObject.buttonDown;
			if (bDown != bMouseDown) {
				xTrace(eventObject.type + ": " + String(bDown));
				bMouseDown = bDown;
			}
		}
		private function createTextField():void {
			addChild(my_txt);
			addChild(label_txt);
			my_fmt.align = TextFormatAlign.RIGHT;
			/*
			my_txt.x +=  50;
			my_txt.defaultTextFormat = my_fmt;
			my_txt.autoSize = TextFieldAutoSize.RIGHT;
			*/
			label_txt.autoSize = TextFieldAutoSize.LEFT;
		}
		private function drawOutline():void {
			var _graphics:Graphics = graphics;
			_graphics.lineStyle(3, 0x0);
			_graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
		}
		private function xTrace(_str:String):void {
			label_txt.appendText(_str + "\n");
		}
	}
}