Eliram
Eliram

Reputation: 616

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

Upvotes: 4

Views: 10470

Answers (2)

enobrev
enobrev

Reputation: 22542

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.

Upvotes: 3

Eliram
Eliram

Reputation: 616

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

The entire article is at:

http://blogs.adobe.com/pdehaan/2006/07/using_flashvars_with_actionscr.html

Important note! This will only work in the main class. If you'll try to load the parameters in a subclass you'll get nothing.

Upvotes: 1

Related Questions