模拟鼠标点击AS3
我在模拟对通过 API 调用(youtube as3 API)生成的按钮(displayObject)的点击调用时遇到问题。我没有看到任何关于安全原因的提及,说明为什么只要使用点击处理程序注册了某些内容,我就无法模拟点击。
基本上,我检查以确保制作的按钮正在侦听鼠标单击事件:
trace( generatedButton.hasEventListener(MouseEvent.CLICK))
返回 true
我继续调用此:
generatedButton.dispatchEvent( new MouseEvent(MouseEvent.CLICK, true) );
如果我物理单击它起作用的按钮,则什么也不会发生。是否有一些安全措施可以防止某些内容被假点击,除非其来源严格来自系统鼠标?
我什至在单击功能上设置了一个超时调用,并将光标移到按钮上并让它触发,以防鼠标必须经过对象但仍然没有任何问题。我现在有点困惑。
任何帮助将不胜感激!
I'm having trouble simulating a click call to a button(displayObject) thats generated via an API call( youtube as3 API). I have not seen any mention of security reasons as to why I can not simulate a click as long as something is registered with a click handler.
Basically I checked to make sure the button made is listening to a mouse click event with:
trace(generatedButton.hasEventListener(MouseEvent.CLICK))
which returns true
I proceed to than call this:
generatedButton.dispatchEvent( new MouseEvent(MouseEvent.CLICK, true) );
And nothing happens yet if I physically click the button it works. Is there some security measure that prevents something from being fake clicked unless its origin is strictly from the system mouse?
I even set a timeout call on the click function and moved my cursor over the button and let it fire in case it was an issue of the mouse having to over the object but still nothing. I am kind of stumped at this point.
Any help would be appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
好吧,我做了一个快速的 FLA 并编写了这段代码,调度鼠标事件完美地工作了。YouTube
api 必须阻止这样的事情
Ok well I made a quick FLA and wrote this code and the dispatch Mouse event works perfectly..
YouTube api must block against something like this
以下代码在我的本地沙箱中运行良好。
所以我只能得出两个结论。
首先是安全问题。 Flash 存在一些安全问题,点击事件会触发 FileReference 类,只有在堆栈中有用户点击时才能使用该类。此问题可能会延续到该事件的任何人工调度。它在我的沙箱中有效,因为该限制不适用于此处。
第二个是您即将调度事件,并且按钮侦听器尚未从 api 添加到按钮。
在这种情况下,请尝试在调用舞台渲染事件后调用调度。
无论如何,这只是我的猜测。
The following code works fine in my local sandbox.
So I can only come to 2 conclusions.
First is a security issue. Flash has some security issues with click events triggering the FileReference class where it can only be used if the stack has a user click in it. This issue may carry over to any artificial dispatching of that event. It works in my sandbox because the restriction doesn't apply here.
The second one is you are dispatching the event to soon and the buttons listener hasn't been added to the button from the api.
In this case try calling the dispatch after the stage render event has been called.
Just my guess anyway.
不要执行dispatchEvent(无论如何它最终都会调用一个方法),只需调用该方法,因为它需要一个MouseEvent,所以执行
yourClickMethod(null)
instead of doing a dispatchEvent, which will eventually call a method anyway, just call the method and since its expecting a MouseEvent, do
yourClickMethod(null)
您无法在服务器上模拟点击事件,这是因为安全问题。您可以直接调用方法,而不是dispatchingEvent。我会查找描述,但它是非法的。您可以检查 Firefox Firebug 日志以获取错误描述。
You can't simulate click events on a server, it is because security issues. Instead of dispatchingEvent you can call method directly. I ll look for the description but its illegal. You can check firefox firebug logs for error description.