Given the coordinates of the scene (x, y), I want my flash application to act as if the user clicked on the position (x, y). That is, something like
function simulateClick(x:Number, y:Number):void{ var e:MouseEvent = new MouseEvent(MouseEvent.CLICK, true, false, x, y) stage.dispatchEvent(e); }
I found a bunch of pages telling about this, and they all give solutions similar to those described above. However, this is not equivalent to user click (x, y). There are two problems:
First, e.stageX and e.stageY are zero. I can not install them directly. The documentation says that they are calculated when installing e.localX and e.localY, but this does not happen when I install e.localX before sending it to the receiver or event listener.
I could rewrite all my event listeners like this:
var p:Point = e.target.localToGlobal(new Point(e.localX, e.localY));
Is this the only option?
The second problem is that my event listeners register with the children of the scene, not the scene itself. Therefore, I need to find out for what purpose to call dispatchEvent. Clearly, Flash is able to determine what the target should be, i.e. Which object belongs to the topmost pixel, visible at (x, y), because it does this when the user actually clicks. Is there an easy way to get this information, or should I just write my own recursive function to do the same? I am using DisplayObjectContainer.getObjectsUnderPoint at the moment, but this is not entirely correct.
I write in FlashDevelop if that matters.