views:

32

answers:

1

First off I don't understand classes, how to "call" or "initiate" them. I'm class ignorant.

I have two .fla files. One of my .fla files consist of 15+ .as files; we'll call this one XML editor. The other .fla file consists of 10+ .as files; we'll call it the interface.

The xmleditor.swf loads the interface.swf. Within the xmleditor.swf, a login screen appears and the enduser logs in as either a "user" or an "admin". The "user" or "admin" is stored in a public variable called "userType". The userType variable is created in one of the many xmleditor.fla .as files called Login.as.

Once logged in, xmleditor loads the interface.swf. interface.fla uses 10+ .as files. one is called nodeNames.as I need an if statement in nodeNames.as that is something like this:

if (Login.userType == "user"){
     trace("do something");
}

I have the following FlashVars.as file but I have no idea what the steps are to make it work.

package extras.utils {
    import flash.display.Sprite;
    import flash.display.LoaderInfo;
    /* In AS3, we need to have a display object on the stage to access FlashVars
         * this class can be used once, and then referenced from anywhere as 
         * FlashVars.data.variableName
        */  
    public class FlashVars extends Sprite {
        public static var data:Object;

        public function FlashVars() { }

        public function load():void { //Only needs to be called once
            data = this.root.loaderInfo.parameters;
        }       

    }
}

Should I use this FlashVars? and if so, how?

Or is there an easier way to access the variable?

A: 

well, from what i understand, you Login.as is a class. Then you have two ways of accessing the Login.userType variable : if you want to be able to call it with Login.userType, you'll need it to be static in your class

public static var userType:String

it is then accessible using Login.userType from anywhere in your application, as long as you import Login.

But it is often considered bad practice to have too many static vars in your app, especially from different classes. so you may want to have an instance of your login class stored in a variable somewhere in your app, along with anything you need

var myLogin = new Login();
myLogin.userType = 'value';

But be aware that this way, every new Login() will carry it's own different userType, so you will want to pass along myLogin to any object needing it.

Object programming can be confusing, but is very powerful, i suggest you read about it (in books or on the web) since the whole thing can't be explained here.

Have fun!

Boris
according to my Login.as file, userType is already a public static var. Login.as is normally imported into my xmleditor.fla; but i need to use the variable in my interface.flaWhen I import Login.as into my interface.fla, i get all sorts of compile errors...i assume because the buttons required for Login.as only exist in xmleditor.fla and not interface.fla where I need access to the Login.userType variable.
Phil
From my interface.swf I can add the following lines of code:trace(this.root.parent); //outputs [object Loader] trace(this.root.parent.parent); //[object xmleditor]
Phil