jump to navigation

FlashVars, SWFObject, and AC_RunActiveContent in ActionScript3 July 19, 2010

Posted by Tournas Dimitrios in Flash, Flex.
trackback

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 a previous article.  FlashVars is useful to pass custom data and to customize the content of a SWF file.

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.

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=tournasdim&score=88',
	); //end AC code

Above I added two variables into the FlashVar, name=tournasdim and score=88.

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", "tournasdim");
swfObject.addVariable("score", "88");
swfObject.write("flashcontent")

Above I added two variables into the FlashVar, name=tournasdim and score=88.

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

Related Posts From this blog:

Advertisements

Comments»

No comments yet — be the first.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s