FlashVars

If you have a Flash applet that must behave differently in different situations, but is still essentially the same animation, you should use parameters to tell your animation what you want it to do in each case. A parameter is some piece of information… a background color for instance… that is passed into the Flash animation from somewhere else (typically, from the web page in which it is hosted). The Flash file uses that information just like any normal variable that was declared inside the file.

There’s a trick to using parameters in Flash… but fortunately, it’s an easy trick:

Passing the Variable

You use a parameter named FlashVars to pass data into a Flash file. Look at the following code that is used to embed a Flash animation on a page:


<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,0,0" width="128" height="128" id="rss1" align="middle">
<param name="allowScriptAccess" value="sameDomain" />
<param name="movie" value="rss1.swf" />
<param name="quality" value="high" />
<param name="bgcolor" value="#ffffff" />
<param name="FlashVars" value="color=#ffff11&url=http://www.rss.com&beh=1&interval=33" />
<param name="wmode" value="transparent" />
<embed src="rss1.swf" quality="high" wmode="transparent" bgcolor="#ffffff" width="128" height="128" name="rss1" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" FlashVars="color=#ffff11&url=http://www.rss.com&beh=1&interval=33" pluginspage="http://www.macromedia.com/go/getflashplayer" />
</object>

The FlashVars parameter appears twice in the above code. That’s because Flash animations have to be embedded TWICE. Internet Explorer recognizes one method, and Firefox recognizes the other.

For Firefox and other REAL web browsers, the <embed> tag is used to place the animation on the page. The FlashVars parameter is simply a named parameter in that tag:


FlashVars="color=#ffff11&url=http://www.technowledgebase.com&beh=1&interval=33"

For Internet Explorer, the FlashVars parameter is added to the <object> </object> code with the line:


<param name="FlashVars" value="color=#ffff11&url=http://www.technowledgebase.com&beh=1&interval=33" />

Look closely at the “value” that I’m passing in each case. Even though there is only one FlashVars parameter, I am passing in multiple variables by putting an ampersand (”&”) between them in the “value” field. So, in my Flash code, I will have:

  • a variable named “color” with a value of “#ffff11″,
  • a variable named “url” with a value of “http://www.technowledgebase.com”,
  • a variable named “beh” with a value of “1″, and
  • a variable named “interval” with a value of “33″

I don’t need to do anything special in my Flash actionscript code to use these variables… they already exist when the code executes and thus can be referenced by name just like any other variable… with one caveat. The numbers that I am passing in (0xffff11, 33 and 1) are passed as strings, so I have to convert them to integers in my actionscript code. I use the ParseInt function, since it allows me to convert the hexidecimal color value that I’m passing into regular base-10 digits.

Popularity: 7% [?]

  • No Related Posts Found
  • Leave a Reply