I’ve been making some games using OpenFL and building to Flash. I would like to make an auto-clicker class to test my games. Is there a good way to simulate clicks on specific stage positions? Simulate drag and drops would be a plus!
I don’t wanna force every Sprite to dispatch click events, I want to simulate mouse clicks on specific x,y positions that trigger event listeners automatically.
On non-Flash targets, you can use Lime window events directly to simulate user events:
stage.window.onMouseDown.dispatch (100, 100, 0);
onMouseDown takes an
y and a mouse button ID, for example. This should work on HTML5 and native, but on the Flash target, I’m not sure if we can simulate basic mouse interaction, the closest thing is to
dispatchEvent (new MouseEvent (MouseEvent.MOUSE_DOWN)); (for example) from a specific object, but that may be more of a problem to try and simulate it perfectly
You can use
stage.getObjectsUnderPoint() to figure out which object to dispatch from.
You’ll have to do some extra work to figure out which is the deepest-nested object in that array that isn’t actually covered up by another. My guess is that you’d want to look for the first object that isn’t a parent of anything else in the array.
The reason you want to find this object is that events bubble up. If you dispatch the event for the deepest-nested object, all of its parents will hear the event too. On the other hand, if you dispatch it for every object in the array, some objects will hear the event multiple times.
I’m going to try your solution, it seems to handle the trick. Thank you!