views:

296

answers:

1

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.

+2  A: 

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.

Chris Gutierrez