Jump to content


Photo

Javascript setVariable() to flash question


  • Please log in to reply
3 replies to this topic

#1 ofanged1

ofanged1

    Young Padawan

  • Members
  • Pip
  • 7 posts
  • Location:Miami Florida

Posted 27 December 2006 - 12:52 PM

I am using the following code to play a sound clip in flash based on which link the user places their mouse over.
[codebox]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 StartSpeakerBox(data){
var flashMovie=getFlashMovieObject("speakerBox");
flashMovie.SetVariable("songId", data);
flashMovie.TCallFrame("/", 11);
flashMovie.Play();
}[/codebox]
In my flash document I have a textbox with var set to "songId". This text box properly displays the song id, although I am not able to use this variable to select to currently playing song.
[codebox]_root.createEmptyMovieClip("sound_mc", 1);
_root.sound_mc.sound_obj = new Sound();
_global.song_nr = songId; //I think this is incorrect usage
_root.sound_mc.player(songfile[song_nr], songname[song_nr]);
[/codebox]
I marked the above with the part I think im doing wrong. It would be great if I could pass data to a var type variable any help will be appriciated. thanks!

#2 Ben

Ben

    P2L Jedi Master

  • Publishing Betazoids
  • PipPipPipPip
  • 1,366 posts
  • Gender:Male
  • Location:VIC, Australia

Posted 27 December 2006 - 08:21 PM

I believe the only way is to keep reloading the Flash everytime you need to change the sound. Your link would be flash.swf?songId= then add the song id via Javascript.

Ben.

#3 ofanged1

ofanged1

    Young Padawan

  • Members
  • Pip
  • 7 posts
  • Location:Miami Florida

Posted 27 December 2006 - 09:02 PM

I believe the only way is to keep reloading the Flash everytime you need to change the sound. Your link would be flash.swf?songId= then add the song id via Javascript.


I added a dynamic textbox to the stage just ouside of viewable space. Gave it an instance name of "songId" When startSpeakerBox is called the value of the textbox is updated to the data value passed to StartSpeakerBox. then songId is passed to _global.song_nr as in the above code.
Works Great! :) Thanks for the quick reply d4rk!

#4 Ben

Ben

    P2L Jedi Master

  • Publishing Betazoids
  • PipPipPipPip
  • 1,366 posts
  • Gender:Male
  • Location:VIC, Australia

Posted 27 December 2006 - 09:11 PM

Well didn't look like you really needed my help :)

Glad you got it working :P

Ben.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users