Created
November 2, 2011 16:19
-
-
Save nsdevaraj/1334083 to your computer and use it in GitHub Desktop.
Dispatch Mouse Event on any X, Y Coordinates
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
protected function clickHandler(event:MouseEvent):void | |
{ | |
var pt:Point = new Point(); | |
pt.x = 201; | |
pt.y =101; | |
var ev:MouseEvent = new MouseEvent(MouseEvent.CLICK); | |
dispatchEventUnderMouse(ev,stage,pt) | |
} | |
public static function dispatchEventUnderMouse(event:Event, stage:Stage, point:Point):Boolean { | |
//return if stage is disabled | |
if (!stage.mouseEnabled) return false; | |
//find the topmost object | |
var cur:DisplayObject = stage.getObjectsUnderPoint(point).pop(); | |
if (cur == null) cur = stage; | |
//build the path | |
var path:Array = []; | |
while (cur != null) { | |
path.push(cur); | |
cur = cur.parent; | |
} | |
//traverse the path from the root to find the right InteractiveObject | |
while (path.length > 0) { | |
cur = path.pop(); | |
if (cur is InteractiveObject) { | |
if (!(cur as InteractiveObject).mouseEnabled) { | |
cur = cur.parent; | |
break; | |
} | |
if (cur is DisplayObjectContainer) { | |
if (!(cur as DisplayObjectContainer).mouseChildren) break; | |
} | |
} | |
else { | |
cur = cur.parent; | |
break; | |
} | |
} | |
return cur.dispatchEvent(event); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment