Return to Kroll Design home page

Flash Tutorials (with .FLA files included)

« Return

ActionScript 3

LoaderInfo class to pass data from HTML to Flash movie

This Flash movie retrieves data stored in the HTML. The Flash LoaderInfo class retrieves data stored in the "flashvars" parameter of the HTML. Because of how Adobe currently configures the HTML and JavaScript which runs the Flash movie, you have to include the flashvars parameters in three places:

  1. the parameter list for JavaScript function AC_FL_RunContent. This is used when the user has JavaScript enabled.
  2. the "param" parameter. This is used when a user with Internet Explorer has JavaScript disabled. However, in Internet Explorer I've noticed that you might think you disabled Javascript, and yet it's still active. Instead of wasting the next 3 hours researching the predictably over-complex security settings in IE, I'll leave that to you if you so desire. God forbid that IE has a nice simple checkbox like Firefox's "Enable JavaScript", lol.
  3. the "embed" parameter. This is used when a user with Firefox or Safari has JavaScript disabled.
The 3 data values appearing in the Flash movie's dynamic text boxes will vary, depending on which of the 3 scenarios described above the user's browser is. The data in the hmtl are name value pairs, with an ampersand separating each pair. For example:
'flashvars', 'myParameter1=red&myParameter2=small&myParameter3=slow',

Download the FLA file

From the HTML of this web page:

<script language="javascript">
if (AC_FL_RunContent == 0) {
	alert("This page requires AC_RunActiveContent.js.");
} else {
		'codebase', ',0,0,0',
		'width', '700',
		'height', '250',
		'src', 'as3_loader_info',
		'quality', 'high',
		'pluginspage', '',
		'align', 'middle',
		'play', 'true',
		'loop', 'true',
		'scale', 'showall',
		'wmode', 'window',
		'devicefont', 'false',
		'id', 'as3_loader_info',
		'bgcolor', '#cccccc',
		'name', 'as3_loader_info',
		'menu', 'true',
		'allowFullScreen', 'false',
		'movie', 'movies/as3_loader_info',
     'flashvars', 'myParameter1=javascript&myParameter2=enabled!&myParameter3=dog', // NOTE FLASHVARS HERE AND TWO OTHER PLACES      
		'salign', ''
		); //end AC code
	<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase=",0,0,0" width="700" height="250" id="as3_loader_info" align="middle">
  <param name="flashvars" value="myParameter1=noscript&myParameter2=param%20tag&myParameter3=cat" />
	<param name="allowScriptAccess" value="sameDomain" />
	<param name="allowFullScreen" value="false" />
	<param name="movie" value="movies/as3_loader_info.swf" /><param name="quality" value="high" /><param name="bgcolor" value="#cccccc" />	<embed src="movies/as3_loader_info.swf" flashvars="myParameter1=also%20noscript.&myParameter2=embed%20tag&myParameter3=elephant" quality="high" bgcolor="#cccccc" width="700" height="250" name="as3_loader_info" align="middle" allowScriptAccess="sameDomain" allowFullScreen="false" type="application/x-shockwave-flash" pluginspage="" />

From the Action Script:

// define text format to be used by all 3 text boxes:

var myTextFormat:TextFormat = new TextFormat("Arial",18,0,true);

// define the 3 text boxes:

var flashvars1_txt:TextField = new TextField;    
flashvars1_txt.defaultTextFormat = myTextFormat;
flashvars1_txt.x = 250;
flashvars1_txt.y = 100;
flashvars1_txt.width = 400;
flashvars1_txt.height = 30;
flashvars1_txt.border = true;
flashvars1_txt.background = true;
flashvars1_txt.backgroundColor = 0xffffff;

var flashvars2_txt:TextField = new TextField;
flashvars2_txt.defaultTextFormat = myTextFormat;
flashvars2_txt.x = 250;
flashvars2_txt.y = 150;
flashvars2_txt.width = 400;
flashvars2_txt.height = 30;
flashvars2_txt.border = true;
flashvars2_txt.background = true;
flashvars2_txt.backgroundColor = 0xffffff;

var flashvars3_txt:TextField = new TextField;   
flashvars3_txt.defaultTextFormat = myTextFormat;
flashvars3_txt.x = 250;
flashvars3_txt.y = 200;
flashvars3_txt.width = 400;
flashvars3_txt.height = 30;
flashvars3_txt.border = true;
flashvars3_txt.background = true;
flashvars3_txt.backgroundColor = 0xffffff;

// store the LoaderInfo data from the html into myLoaderInfo:

var myLoaderInfo:Object = LoaderInfo(this.root.loaderInfo).parameters;

// copy each parameter from myLoaderInfo to a text field: 	 

var myParm1:String  = myLoaderInfo["myParameter1"];
flashvars1_txt.text = myParm1;

var myParm2:String  = myLoaderInfo["myParameter2"];
flashvars2_txt.text = myParm2;

var myParm3:String  = myLoaderInfo["myParameter3"];
flashvars3_txt.text = myParm3;

« Return

©2012 Kroll Design    781.910.3694
Last modified: 12/31/1969 7:00 PM