views:

984

answers:

1

Hello all. 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"&gt;
<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"&gt;
</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?

+2  A: 

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);
Luke
Thanks for the reply!!! using 3 arguments with ExternalInterface.addCallback gives the following error:1137: Incorrect number of arguments. Expected no more than 2.
danwoods
using 'ExternalInterface.addCallback("jsAlert", jsAlert);' fixed the problem. Thanks so much!!! the documentation says the second of the three arguments gives a point of reference. Could you elaborate on that at all?
danwoods
Dan. Sorry about the parameter comment, you are right. I had AS2 in my head which needs three instead of two parameters. Glad it works now!
Luke