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?
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