2012-08-09 33 views

回答

0

請試試這個:

ExternalInterface.addCallback("sendMsg", generateMsg); 

function generateMsg(str):void { 
    trace(str); 
} 

JS:

msg = ""; 
function setMsg(myMsg) { 
    msg = myMsg; 
    SendDataToFlashMovie(myMsg); 
} 
+0

你忘了告訴他怎麼辦在JS – 2012-08-09 19:56:04

+0

嗨,愛德華,怎麼樣的JavaScript文件(爲了發送參數)。 - 編輯:馬塞洛已經指出了這一點,抱歉的雙重評論。 – 2012-08-09 20:04:03

+0

對不起,我的壞..糾正 – 2012-08-09 20:27:15

0

以我的經驗,你必須調用Flash對象的功能。

我用下面的JavaScript函數來獲取Flash對象

function GetSWF(id) { 
    if (window.document[id] != null) 
     if (window.document[id].length == null) 
      return window.document[id]; 
    else 
     return window.document[id][1]; 
    else 
    if (typeof(document[id]) == 'undefined') 
     return $('#'+id)[0]; 
    else 
    if (document[id].length == null) 
     return document[id]; 
    else 
     return document[id][1]; 
} 

然後調用函數如下

var flash = GetSWF('idOfSWF'); 
if (typeof flash.sendToActionScript === 'function'){ 
    flash.sendToActionScript(yourObject,orParameter); 
} 

的AS3會是什麼樣如下

if (ExternalInterface.available){ 
    ExternalInterface.addCallback("sendToActionScript",receivedFromJavascript); 
} 
function receivedFromJavascript(myObject:Object,myParameter:String):void{ 
    // Do something 
} 

希望這幫助。

編輯:

只注意到我的jQuery在GetSWF功能的小用法。我會看看並嘗試刪除它。 (它的線return $('#'+id)[0];

相關問題