I need to send a variable from a javascript function to a flash movie embedded in the same HTML page. I downloaded a demo from Macromedia, but it sends the variable from a textfield, either onChange or onSubmit. How can I adapt this to send the variable when the page loads?...
code:
<HTML>
<HEAD>
<TITLE>javascript_to_flash</TITLE>
</HEAD>
<SCRIPT LANGUAGE=JavaScript>
<!--
function doPassVar(args){
var myLoad = "imageList2.txt";
window.document.myFlash.SetVariable("myVar", myLoad);
}
//-->
</SCRIPT>
<BODY bgcolor="#FFFFFF">
//attempt to send the variable when the HTML page loads
<window.document.onLoad=window.document.myFlash.Se tVariable("myVar", myLoad)>
//the form field below correctly sends the variable
<form name="form1" onLoad="doPassVar(myLoad);" action="#">
<input type="text" name="myLoad" maxlength="45" onChange="doPassVar(this);">
</form>
<p><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000"
codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0"
width=400 height=180 id="myFlash">
<param name=movie value="javascript_to_flash.swf">
<param name=quality value=high>
If I understand your question correctly (How can I adapt this to send the variable when the page loads?...), then... <BODY bgcolor="#FFFFFF" onLoad="doPassVar(this)">
If you try something different - take a look at the attached example
is there any need for javascript? if you're just passing in a variable when the page loads could it be done using flashvars instead (which should be more reliable across different browsers - eg it won't fail if javascript is turned off)
I have only recently looked into this. The main movie loads an imageList text file containing image names. It was requested to be able to change which imageList text file is to be used when embedding the .swf into the html page. So, for example, you could have the same movie embedded in 3 different places, each using a different text file with the images to be used.I finally got this working with javascript passing the variable to the flash movie thanks to sergwiz post. However, I have read about some possible browser issues with this method and, like you say,.... someone turning off javascript in thier browser. I looked into your suggestion, but I can't seem to get it to work...... been one of those days when nothing seems to work for me. Here is what I have tried.......
You wouldn't need swliveconnect if you're using flashvars. other than that your code looks ok - so it *should* be creating the variable myLoad on the main timeline of your movie.
After some playing around, I finally figured out I was handling the variable incorrectly in the Flash movie. I now have it working for the Javascript method and passing the variable as a parameter.