从JS调用AS3 MouseEvent函数

时间:2010-01-09 16:05:35

标签: javascript flash actionscript-3 mouseevent

有没有办法从JavaScript调用as3中的MouseEvent函数? 我有HTML按钮和swf对象,我需要通过单击HTML按钮从swf发送POST请求。

1 个答案:

答案 0 :(得分:3)

您可以使用ExternalInterface api。

执行此操作

在您的Flash对象中,拨打以下电话。

ExternalInterface.addCallback("someAPIMethod", anActionScriptMethod);

function anActionScriptMethod():void
{
    // handle POST
}

然后在您的JavaScript中,您需要获取嵌入式闪存的对象并调用您在闪存中定义的“someAPIMethod”回调。

你的标记可能看起来像......

<button id="someId" value="Click Me" onclick="onButtonClick();">Click Me</button>

你的JS可能看起来像......

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);
}

您可能需要对此代码进行调整,但它应该为您提供一些入门指导。