ActionScript
FlashVars, SWFObject, and AC_RunActiveContent in ActionScript3
June 6, 2009
0

Background

FlashVars is a mechanism to pass variables to a Flash SWF file.  It is similar to a query-string and you can read more about it on this tutorial.  FlashVars is useful to pass custom data and to customize the content of a SWF file.

For overview of the FlashVars, look here.

In the old days, FlashVars is normally added into object and embed tags within the html page that contains the movie.  However, nowadays, most Flash SWF files are embedded by using some JavaScript mechanism of sort.  The was due to the EOLAS (Embeded Objects Linked Across Systems) patent which Microsoft chose to no license in Internet Explorer, thus causing many Flash SWF files to require user to click on the browser before the SWF becomes active.  That started happening in 2003, and workarounds have been made to not require user to click on the Flash SWF file, by essentially having Javascript write the “embed” code.  It’s lost on me how much different this is from embedding in the html page; but anyhow, as time passed, various scripts are used as workaround to embed Flash SWF files.  Two of the most popular ones are SWFObject and AC_RunActiveContent.

FlashVars In AC_RunActiveContent

AC_RunActiveContent.js is/was the official Adobe solution.  It is included in Flash CS3 and it is automatically deployed to your publish folder when publishing for Flash.

acactivecontent

The html page usually looks like this:

		AC_FL_RunContent(
			'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,115,0',
			'width', '550',
			'height', '400',
			'src', 'SWFmovie',
			'quality', 'high',
			'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
			'align', 'middle',
			'play', 'true',
			'loop', 'true',
			'scale', 'showall',
			'wmode', 'window',
			'devicefont', 'false',
			'id', 'SWFmovie',
			'bgcolor', '#ffffff',
			'name', 'SWFmovie',
			'menu', 'true',
			'allowScriptAccess','sameDomain',
			'allowFullScreen','false',
			'movie', 'SWFmovie',
			'salign', ''
			); //end AC code

To add FlashVars, just add it anywhere like below:

		AC_FL_RunContent(
			'codebase', 'http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,115,0',
			'width', '550',
			'height', '400',
			'src', 'SWFmovie',
			'quality', 'high',
			'pluginspage', 'http://www.macromedia.com/go/getflashplayer',
			'align', 'middle',
			'play', 'true',
			'loop', 'true',
			'scale', 'showall',
			'wmode', 'window',
			'devicefont', 'false',
			'id', 'SWFmovie',
			'bgcolor', '#ffffff',
			'name', 'SWFmovie',
			'menu', 'true',
			'allowScriptAccess','sameDomain',
			'allowFullScreen','false',
			'movie', 'SWFmovie',
			'salign', ''
			'FlashVars', 'name=Jim&score=10',
			); //end AC code

Above I added two variables into the FlashVar, name=Jim and score=10.

FlashVars In SWFObject

SWFObject is created by Geoff Stearns and is becoming the standard for including SWF content in html page. It is hosted at http://osflash.org/swfobject. FlashCS4 suposedly uses SWFObject, replacing RunActiveContent.

Adding FlashVars in SWFObject is as simple as calling addVariable(variableName, variableValue). Example:

   var swfObject = new SWFObject("SWFmovie.swf", "SWFmovie", "550", "400", "9", "#ffff");
   swfObject.addVariable("name", "Jim");
   swfObject.addVariable("score", "10");
   swfObject.write("flashcontent");

Above I added two variables into the FlashVar, name=Jim and score=10.

More SWFObject examples at: http://blog.deconcept.com/swfobject/#examples