Moving From Flash AS2 to Flash AS3: FlashVars

Published by Angel on Tagged Actionscript 3.0, Moving From AS2 to AS3

What is FlashVars?

FlashVars is Flash answer to Query String.  It's a way to pass data or variables from html to a Flash movie.  Variables passed via FlashVars will go into the _root level of the Flash movie.

Differences Between AS2 and AS3

The key difference between AS2 and AS3 is how to retrieve the FlashVars. The FlashVars are no longer available in the _root level of the movie. Instead, you must use the new LoaderInfo class object to access the FlashVars.  The FlashVars is available in the parameters member of the LoaderInfo. This makes the AS3 solution much more dynamic and independent to each object that is created. See below for an example of both.

FlashVars in AS2

var myFlashVar:String;
_root.createTextField("myTextField", 1, Stage.width/2 - 50, Stage.height/2 , 150, 40);
myTextField.text = myFlashVar;


FlashVars in AS3

function loaderComplete(myEvent:Event)
{
   this.flashVars=this.loaderInfo.parameters;
   this.flashVarsLoaded=true;  // set a flag to indicate that the FlashVars is loaded
   this.useFlashVars();
}


I hope this post helped you understand the key difference between defining your FlashVars within AS2 and AS3.  If your interested in learning more about FlashVars, check out the resources below as they will go deeper into the topic.

Resources on FlashVars:

I would like to hear from you on how I can make the series of posts "Moving From Flash AS2 to Flash AS3" better.  Looking forward to hearing from you!



Related Posts




One Response to “Moving From Flash AS2 to Flash AS3: FlashVars”

  1. FLV Player With YouTube Support | Flash Speaks Actionscript Says:

    [...] it is very customizable allowing you to customize many properties via the query string/FlashVars.  If you are looking for a sleek, customizable FLV player for your personal and YouTube [...]

Leave a Comment