2011-06-15 39 views
2

我在收到Javascript恢復Flash文件時遇到了很大問題。 Flash文件加載並將視頻設置爲自動播放false。出於某種原因,任何Javascript都不會識別AS3功能。它一直說這個函數是未定義的。例如在閃存中播放停止的視頻

function getFlashMovie(movieName) { 
    var isIE = navigator.appName.indexOf("Microsoft") != -1; 
    return (isIE) ? window[movieName] : document[movieName]; 
} 

function callToActionscript(str) 
{ 
    getFlashMovie("video").sendToActionscript(str); 
} 

sendToActionscriptundefined

任何幫助將是偉大的。

感謝 馬克

+0

是來自同一個域的視頻和JavaScript?你允許在你的swf中訪問腳本嗎?你確定在swf裏面有這個函數嗎? – 2011-06-15 14:51:44

+0

嗨伊戈爾。它的全部在同一個域名 – Mark 2011-06-15 16:08:44

+0

和其他我的問題?我想你忘了添加回調到瑞士法郎..看這個http://stackoverflow.com/questions/918588/javascript-to-flash-via-externalinterface – 2011-06-15 17:32:31

回答

1

使用JavaScript來播放視頻,你需要做三件事情。

首先建立在您的Flash文件中的ActionScript方法,如:

import flash.external.ExternalInterface; 

// create the callback to allow the js to call the method 
ExternalInterface.addCallback("playMyVideo", playMyVideo); 

function playMyVideo():void 
{ 
video.play();//where video is the name of the video component 
} 

下創建javascript函數來調用AS方法:

function getFlashMovie(movieName) { 
    var isIE = navigator.appName.indexOf("Microsoft") != -1; 
    return (isIE) ? window[movieName] : document[movieName]; 
} 

//js function to call the AS3 method 
function callToActionscript() 
{ 
//NB this is the name of the swf in the HTML and not the video component 
getFlashMovie("mySWF").playMyVideo(); 
} 

最後,你需要讓SWF到在HTML頁面中與Javascript通信。 allowScriptAccess參數必須設置。默認情況下,它被設置爲'sameDomain',它只有在SWF與主機網頁位於同一個子域時才允許腳本。將其設置爲「始終」可讓所有腳本從SWF中調出。

+0

嗨馬丁。恐怕還是同樣的錯誤。我已經完全複製了AS3代碼。你可以看看我的網址http://www.thehub.ignitiondrivingschools.co.uk/hazard-perception – Mark 2011-06-16 08:09:07

+0

電腦說「錯誤連接數據庫」 – 2011-06-16 09:23:33

+0

啊對不起。所有固定的...我正在做其他事情 – Mark 2011-06-16 10:49:36