2010-01-09 60 views
0

有什麼辦法可以在JavaScript中調用as3中的MouseEvent函數嗎? 我有HTML按鈕和swf對象,我需要通過單擊HTML按鈕發送swf的POST請求。從JS調用AS3 MouseEvent函數

+0

你想去哪個方向?使用JS單擊Flash或使用Flash單擊HTML? – grapefrukt 2010-01-09 16:14:50

+0

我想在html中單擊並在閃存中發送POST請求 – Alex 2010-01-10 02:24:40

回答

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

有可能會是你需要對這個代碼的調整,但它應該給你一些開始的方向。