使用 ActionScript 单击 AIR 中的 HTML 元素
我正在尝试为 AIR 应用程序中的 HTML 组件调度 MouseEvent。这样我想用 ActionScript 代码模拟 HTML 元素的点击。这是我的 AIR 应用程序代码:
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
<fx:Script>
<![CDATA[
private function clickHTML(event:MouseEvent):void {
var e:MouseEvent = new MouseEvent(MouseEvent.CLICK,true,false,10,10);
html.dispatchEvent(e);
}
]]>
</fx:Script>
<s:Button label="Click HTML" x="10" y="10" click="clickHTML(event)"/>
<mx:HTML id="html" x="10" y="50" width="100" height="100"
location="page.html" click="trace('html was clicked')"/></s:WindowedApplication>
这是 page.html 的代码:
<html>
<body onClick="alert('Clicked!')" bgcolor="grey">
Page loaded
</body>
</html>
当您自己单击 HTML 元素时,会出现警报和 MouseEvent,但是当使用脚本调度事件时,只有 MouseEvent。
如何让它发挥作用?
I'm trying to dispatch MouseEvent for HTML component in an AIR application. This way I want to simulate a click on HTML elements with ActionScript code. Here is my AIR app code:
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
<fx:Script>
<![CDATA[
private function clickHTML(event:MouseEvent):void {
var e:MouseEvent = new MouseEvent(MouseEvent.CLICK,true,false,10,10);
html.dispatchEvent(e);
}
]]>
</fx:Script>
<s:Button label="Click HTML" x="10" y="10" click="clickHTML(event)"/>
<mx:HTML id="html" x="10" y="50" width="100" height="100"
location="page.html" click="trace('html was clicked')"/></s:WindowedApplication>
Here is the code for page.html:
<html>
<body onClick="alert('Clicked!')" bgcolor="grey">
Page loaded
</body>
</html>
When you click HTML element by yourself, there is an alert and MouseEvent, but when event dispatched with script there is only MouseEvent.
How to make it work?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您需要直接调用 JavaScript 函数才能对您的 html 内容执行某些操作。
查看此文章:
从 ActionScript 访问 HTML DOM 和 JavaScript 对象
You need directly call JavaScript functions in order to your html content do something.
Check this arcticle:
Accessing HTML DOM and JavaScript objects from ActionScript