Is there any way to call MouseEvent function in as3 from JavaScript? I have HTML button and swf object, I need to sent a POST request from swf by clicking on HTML button.
-
What direction do you want to go? Clicking in Flash using JS or clicking in html using Flash?grapefrukt– grapefrukt2010-01-09 16:14:50 +00:00Commented Jan 9, 2010 at 16:14
-
I want to click in html and than send a POST request in flashAlex– Alex2010-01-10 02:24:40 +00:00Commented Jan 10, 2010 at 2:24
Add a comment
|
1 Answer
You can do this with the ExternalInterface api.
In your flash object, make a call like the following.
ExternalInterface.addCallback("someAPIMethod", anActionScriptMethod);
function anActionScriptMethod():void
{
// handle POST
}
Then in your JavaScript, You'll need to get the object of your embedded flash and call the "someAPIMethod" call back you have defined in your flash.
your markup may look something like...
<button id="someId" value="Click Me" onclick="onButtonClick();">Click Me</button>
Your JS may then look like...
function onButtonClick()
{
// get the flash object and call the callback method
flashObj(name).call("someAPIMethod");
}
// this probably won't work in all browsers, search the net for a better function.
function flashObj(name)
{
if (window.document[name])
{
return window.document[name];
}
return document.getElementById(name);
}
there will probably be tweaks that you need to make to this code but it should give you some direction to get started.