ActionScript 3 and FlashVars


FlashVars is synonymous to command line parameters. When a java program is run in this way:
java myJavaApp.class hello

myJavaApp can gain access to the command line parameter, “hello” from it’s args.
public static void main(String [] args) {

A flash program, however, is ran inside a browser. You will have to the pass the “hello” value inside the HTML where you add the SWF object.
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://fpdownload.adobe.com/pub/shockwave/cabs/flash/swflash.cab#version=8,0,0,0" width="550" height="400" id="myflashvars" align="middle">
  <param name="allowScriptAccess" value="sameDomain" />
  <param name="movie" value="myflashvars.swf" />
  <param name="FlashVars" value="myCommandLine=hello">
  <param name="quality" value="high" />
  <param name="bgcolor" value="#ffffff" />
  <embed src="myflashvars.swf" FlashVars="myCommandLine=hello" quality="high" bgcolor="#ffffff" width="640" height="480" name="myflashvars" align="middle" allowScriptAccess="sameDomain" type="application/x-shockwave-flash" pluginspage="http://www.adobe.com/go/getflashplayer" />

Then you will access “hello” on ActionScript this way:
var flashVars:Object = root.loaderInfo.parameters;

When to use FlashVars?

You can use FlashVars to just about any Flash application that requires loading of additional configuration. YouTube, for example, uses FlashVars in their flash video player to determine the path of the FLV file it needs to load.

You must be logged in to post a comment.