Previously, in ActionScript 2.0, you could pass variables along the query string or using FlashVars and the variables would be available in _level0, in ActionScript 3.0, it is a bit different . In Actionscript 3 variables that are passed in through query string have been moved to the parameters property of LoaderInfo instance. Here’s a real simple way to retrieve flash variable in Actionscript 3
1 2 3 4 | <object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" width="550" height="400" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0">
<param name="src" value="somefilename.swf?fileName=info" />
<embed type="application/x-shockwave-flash" width="550" height="400" src="somefilename.swf?fileName=info"></embed>
</object> |
To access the query string fileName in Actionscript 3 , all you have to do in your actionscript 3 source code is
1 2 | var fileName:String = new String(); fileName = root.loaderInfo.parameters.fileName |
Here’s another way to loop through your flash variables
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | var tf:TextField = new TextField(); tf.autoSize = TextFieldAutoSize.LEFT; tf.border = true; addChild(tf); tf.appendText("params:" + "\n"); try { var keyStr:String; var valueStr:String; var paramObj:Object = LoaderInfo(this.root.loaderInfo).parameters; for (keyStr in paramObj) { valueStr = String(paramObj[keyStr]); tf.appendText("\t" + keyStr + ":\t" + valueStr + "\n"); } } catch (error:Error) { tf.appendText(error.toString()); } |






