actionscript-3parametersdocumentationflashvars

How do I use FlashVars with ActionScript 3.0?


I found this guide for using the flash parameters, thought it might be useful to post here, since Flash CS3 lacks a usage example for reading these parameters.

See answers for the link


Solution

  • Not sure why his example calls LoaderInfo. The DisplayObject class has its own (readonly) loaderinfo property. As long as your main class extends a DisplayObject, you can call the property directly

    package {
        import flash.display.Sprite;
    
        public class Main extends Sprite {
    
            public function Main() {
                var test1:String    = '';
    
                if (this.loaderInfo.parameters.test1 !== undefined) {
                    test1 = this.loaderInfo.parameters.test1;
                }
            }
        }
    }
    

    From the doc:

    Returns a LoaderInfo object containing information about loading the file to which this display object belongs. The loaderInfo property is defined only for the root display object of a SWF file or for a loaded Bitmap (not for a Bitmap that is drawn with ActionScript). To find the loaderInfo object associated with the SWF file that contains a display object named myDisplayObject, use myDisplayObject.root.loaderInfo.