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
Tags: actionscript, as2, download, flash, html, open source, tutorial
(5 votes, average: 4.4 out of 5)
