Intro to Flashvars | Passing variables to actionscript from the html embed | Tutorial
I’ve had a couple special requests to explain flashvars and how to use it and show it in action.
Overview
The property “FlashVars” can be used to import root level variables to the flash movie or swf. The flashvars propery is used in codes for embedding flash in the html page. The string of variables passed in as flashvars, will be imported into the top level of the movie when it is first instantiated. Variables are created before the first frame of the SWF is played. The format of the string is a set of name=value combinations separated by ampersand (&) symbols.
Steps
- Include the flashvars property in your embed codes and voila! You have these variables to use in your swf.
- That’s the one step
Code
HTML Embed Codes
- Here's some sample embed codes, including object and embed tags:
- <object width="540" height="240" title="sample">
- <param name="movie" value="flashvarsTutorial.swf" />
- <param name="flashvars" value="var1=here&var2=are&var3=my&var4=flashvars" />
- <embed src="flashvarsTutorial.swf" flashvars="var1=here&var2=are&var3=my&var4=flashvars" type="application/x-shockwave-flash" width="540" height="240" ></embed>
- </object>
Actionscript using flashvars
- //flashvars="var1=val1&var2=val2&var3=val3";
- display("var1 = "+ var1);
- display("var2 = "+ var2);
- display("var3 = "+ var3);
- display("var4 = "+ var4);
- function display(todisplay:String){
- feedback.text += todisplay+"\n";
- trace(todisplay);
- }
Example
Page 1 (var1=val1&var2=val2&var3=val3)
Page 2 (var1=here&var2=are&var3=my&var4=flashvars)
Source
Download the html files and the fla and swf in this flashvars.zip





























Hey.
Nice example for start..!
You have managed your blog very well
Hello, I have the files and everything and i was testing around with the fla file and the html page so it will only show up var 1 and 2 but even tho when i take them out of the fla and html page var 3 and var 4 they still show up and say undefined on it.. help?
If you use CS3 and publish html, you need to add
In the AC_FL_RunContent code the following:
‘FlashVars’, ‘var1=val1&var2=val2&var3=val3′