Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Initializing variables

Status
Not open for further replies.

apatterno

Programmer
Nov 26, 2002
368
US
How can I initialize Flash variables from the HTML page that contains it? For example, I have two variables _root.preloadalbum and _root.preloadsong, to which I would like to assign values, by means of JavaScript.

In the first frame of the flash file, I stop playback and send an FSCommand.

My FSCommand function looks like this:

Code:
function listen_DoFSCommand(command, args) {
		  window.alert("Blah");
		  document.listen.SetVariable("_root.preloadalbum", "ddfa");
		  document.listen.SetVariable("_root.preloadsong", "ddfa-447e");
		  document.listen.Play();
}

The "Blah" pops up, the animation plays, but the variables don't get changed.

Is there something I'm doing wrong?

Thanks in advance
Will
 
You can feed variables into the movie by appending them to the movie name in the object/embed tag. Here's a sample script that brings in variables, sets the movie size and background colour and writes out the HTML dynamically:

<script language=&quot;JavaScript1.1&quot;>
<!--
var strParams = location.search;
var flName = &quot;load.swf&quot;
flColor = &quot;#000000&quot;
flWidth = &quot;750&quot;
flHeight = &quot;425&quot;

document.write('<object'
+ ' classid=clsid:D27CDB6E-AE6D-11cf-96B8-444553540000&quot;'
+ ' codebase=&quot; + ' id=&quot;flash&quot;'
+ ' width=' + flWidth
+ ' height=' + flHeight + '>'
+ ' <param name=&quot;movie&quot; value=&quot;' + flName + strParams + '&quot;>'
+ ' <param name=&quot;quality&quot; value=&quot;high&quot;>'
+ ' <param name=bgcolor value=' + flColor + '>'
+ ' <embed src=&quot;'+ flName + strParams + '&quot;'
+ ' name=&quot;flash&quot;'
+ ' quality=high bgcolor=' + flColor
+ ' width=' + flWidth
+ ' height=' + flHeight
+ ' type=&quot;application/x-shockwave-flash&quot;'
+ ' pluginspage=&quot; + ' </embed></object>'
)
// -->
</script>
 
How are flName and strParams combined?

For example, would it be like [tt]&quot;listen.swf?preloadalbum=ddfa&preloadsong=ddfa-447e&quot;[/tt] ?

And do I access these passed variables in the conventional manner (i.e., by using _root.preloadalbum and _root.preloadsong)?

Thanks for your help wangbar.
 
Never mind, I tested that out and it worked fine!

Thank you!!!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top