开发者

Simulate click event in AS3

开发者 https://www.devze.com 2023-04-07 03:37 出处:网络
Is there any way to simulate a click event in AS3? I\'m trying this: element.dispatchEvent(new MouseEvent(MouseEvent.MOUSE_DOWN, true, false));

Is there any way to simulate a click event in AS3? I'm trying this:

element.dispatchEvent(new MouseEvent(MouseEvent.MOUSE_DOWN, true, false));

B开发者_如何学运维ut click event isn't trigger it.


If you are listening for MouseEvent.CLICK then dispatch MouseEvent.CLICK. You are now dispatching MouseEvent.MOUSE_DOWN

element.dispatchEvent(new MouseEvent(MouseEvent.CLICK));


You must dispatch a MouseEvent.CLICK event.

element.dispatchEvent(new MouseEvent(MouseEvent.CLICK, true, false));


To simulate a CLICK event you need first to dispatch:

element.dispatchEvent(new MouseEvent(MouseEvent.MOUSE_DOWN, true, false));

followed by a:

element.dispatchEvent(new MouseEvent(MouseEvent.MOUSE_UP, true, false));

On the MOUSE_UP event the handler will then issue a click event (if the mouse is OVER the element, so you may need to set the mouse_x and mouse_y variables in the dispatched event.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号