Javascript to flash via ExternalInterface

…衆ロ難τιáo~ 提交于 2019-12-21 06:06:14

问题


I'm wondering if someone could look over my code. I'm trying to pass a dummy variable from javascript to actionscript 3 with the following code:

HTML:
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
id="music_player" width="500" height="375"
codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab">
<param name="movie" value="music_player.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#869ca7" />
<param name="allowScriptAccess" value="always" />
<embed src="music_player.swf" quality="high" bgcolor="#869ca7"
width="500" height="375" name="music_player" align="middle"
play="true" loop="false" quality="high" allowScriptAccess="always"
type="application/x-shockwave-flash"
pluginspage="http://www.macromedia.com/go/getflashplayer">
</embed>
</object>

Javascript:
var nextTrackLocation = "dummyString";
getFlashMovie("music_player").jsAlert(nextTrackLocation);

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

and the actionscript:
ExternalInterface.addCallback("getNextTrack", jsAlert);

function jsAlert(mess){
ExternalInterface.call("alert", mess);
}

Does anyone see a mistake?


回答1:


Your question is very confusing. I think you are making two mistakes here.

From Javascript you're trying to call a function in Actionscript called "jsAlert" but the function is in Actionscript exposed as "getNextTrack". I think it should be:

getFlashMovie("music_player").getNextTrack(nextTrackLocation);

Second, where you define the function in Actionscript you overlooked that the ExternalInterface.addCallback actually takes three parameters.

ExternalInterface.addCallback("getNextTrack", null, jsAlert);


来源:https://stackoverflow.com/questions/918588/javascript-to-flash-via-externalinterface

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!