2

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
  • sorry, the first two lines of the javascript are within the function 'getNextTrack' Commented May 28, 2009 at 1:09

1 Answer 1

2

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);
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for the reply!!! using 3 arguments with ExternalInterface.addCallback gives the following error: 1137: Incorrect number of arguments. Expected no more than 2.
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?
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!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.