Home Contact RSS

Intro to Flashvars | Passing variables to actionscript from the html embed | Tutorial

1 Star2 Stars3 Stars4 Stars5 Stars (5 votes, average: 4.4 out of 5)
Loading ... Loading ...

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

  1. Include the flashvars property in your embed codes and voila! You have these variables to use in your swf.
  2. That’s the one step

Code

HTML Embed Codes

  1. Here's some sample embed codes, including object and embed tags:
  2. <object width="540" height="240" title="sample">
  3.   <param name="movie" value="flashvarsTutorial.swf" />
  4.   <param name="flashvars" value="var1=here&var2=are&var3=my&var4=flashvars" />
  5.   <embed src="flashvarsTutorial.swf" flashvars="var1=here&var2=are&var3=my&var4=flashvars" type="application/x-shockwave-flash" width="540" height="240" ></embed>
  6. </object>

Actionscript using flashvars

  1. //flashvars="var1=val1&var2=val2&var3=val3";
  2.  
  3. display("var1 = "+ var1);
  4.  
  5. display("var2 = "+ var2);
  6.  
  7. display("var3 = "+ var3);
  8.  
  9. display("var4 = "+ var4);
  10.  
  11. function display(todisplay:String){
  12.   feedback.text += todisplay+"\n";
  13.   trace(todisplay);
  14. }

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: , , , , , ,

Related posts

flashden banner

Gravatar

Inder Singh said,

August 7, 2008 @ 7:39 am

Hey.

Nice example for start..!

You have managed your blog very well :)

RSS feed for comments on this post · TrackBack URI

Leave a Comment