2011-05-04 135 views
0

可能重複:
flash javascript don't work閃光的JavaScript不工作(第二次嘗試)

的javascript:

function getFlashMovieObject(movieName) 
{ 
    if (window.document[movieName]) 
    { 
     return window.document[movieName]; 
    } 
    if (navigator.appName.indexOf("Microsoft Internet")==-1) 
    { 
    if (document.embeds && document.embeds[movieName]) 
     return document.embeds[movieName]; 
    } 
    else // if (navigator.appName.indexOf("Microsoft Internet")!=-1) 
    { 
    return document.getElementById(movieName); 
    } 
} 

function TestPlay() 
{ 
    var flashMovie=getFlashMovieObject("myFlashPlayer"); 
    try 
    { 
     document.getElementById("TimeDisplay").innerHTML=flashMovie.GetDuration(); 
    } 
    catch(e) 
    { 
     alert(e.message); 
    } 
} 

HTML:

<object width="150" height="100" id="myFlashPlayer"> 
<param name="movie" value="Sound.swf"/> 
<embed src="Sound.swf" width="150" height="100" name="myFlashPlayer"> 
</embed> 
</object> 
<button onclick="TestPlay()" id="TestBtnPlay">Play</button> 
<span id="TimeDisplay"></span> 

AS 2.0:

_global.track=new Sound(); 
_global.track.onLoad=finished; 
_global.track.loadSound(Path.text,true); 
_global.last_position=0; 
_global.track.stop(); 

ExternalInterface.addCallback("GetDuration", GetDuration); 
stop(); 

function finished() 
{ 
_global.track.stop(); 
} 

function GetDuration() 
{ 
    return _global.track.duration; 
} 
+0

http://tinyurl.com/so-hints – 2011-05-04 17:27:51

+0

你應該修改你原來的問題:閃光的JavaScript不工作(HTTP ://www.stackoverflow.com/questions/5495497/flash-javascript-dont-work) – Orbling 2011-05-04 17:27:51

+0

我採取了不同的接近,所以我想它成爲一個新的問題 – unicorn 2011-06-09 06:52:32

回答

0

試試這個:

function TestPlay() 
{ 
    try 
    { 
     document.getElementById("TimeDisplay").GetDuration(); 
    } 
    catch(e) 
    { 
     alert(e.message); 
    } 
} 
+0

這是沒有道理,GetDuration它是一個Flash函數和TimeDisplay它是一個HTML元素。爲什麼這個工作? – unicorn 2011-05-05 03:08:56

+0

它是有道理的。你在這一行所做的只是告訴你的js讓你的flash對象id =「TimeDisplay」。獲得Flash對象後,只需使用「ExternalInterface.addCallback(」GetDuration「,GetDuration)」訪問您公開的函數;「看看AS2的參考資料:http://flash-reference.icod.de/ – nelsond8 2011-05-05 06:48:43

+0

1.我的falsh id是「myFlashPlayer」,你可能意味着 – unicorn 2011-05-06 04:37:12

相關問題