0

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
  • What direction do you want to go? Clicking in Flash using JS or clicking in html using Flash? Commented Jan 9, 2010 at 16:14
  • I want to click in html and than send a POST request in flash Commented Jan 10, 2010 at 2:24

1 Answer 1

3

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.