actionscript 3 - Accessing Variables in another class? -


first off don't understand classes, how "call" or "initiate" them. i'm class ignorant.

i have 2 .fla files. 1 of .fla files consist of 15+ .as files; we'll call 1 xml editor. other .fla file consists of 10+ .as files; we'll call interface.

the xmleditor.swf loads interface.swf. within xmleditor.swf, login screen appears , enduser logs in either "user" or "admin". "user" or "admin" stored in public variable called "usertype". usertype variable created in 1 of many xmleditor.fla .as files called login.as.

once logged in, xmleditor loads interface.swf. interface.fla uses 10+ .as files. 1 called nodenames.as need if statement in nodenames.as this:

if (login.usertype == "user"){      trace("do something"); } 

i have following flashvars.as file have no idea steps make work.

package extras.utils {     import flash.display.sprite;     import flash.display.loaderinfo;     /* in as3, need have display object on stage access flashvars          * class can used once, , referenced anywhere           * flashvars.data.variablename         */       public class flashvars extends sprite {         public static var data:object;          public function flashvars() { }          public function load():void { //only needs called once             data = this.root.loaderinfo.parameters;         }             } } 

should use flashvars? , if so, how?

or there easier way access variable?

well, understand, login.as class. have 2 ways of accessing login.usertype variable : if want able call login.usertype, you'll need static in class

public static var usertype:string 

it accessible using login.usertype anywhere in application, long import login.

but considered bad practice have many static vars in app, different classes. may want have instance of login class stored in variable somewhere in app, along need

var mylogin = new login(); mylogin.usertype = 'value'; 

but aware way, every new login() carry it's own different usertype, want pass along mylogin object needing it.

object programming can confusing, powerful, suggest read (in books or on web) since whole thing can't explained here.

have fun!


Comments

Popular posts from this blog

c++ - How do I get a multi line tooltip in MFC -

asp.net - In javascript how to find the height and width -

c# - DataTable to EnumerableRowCollection -