Global Objects/Variables


i have looked on forum , in other places , cannot find answer question. possible set instance of object or variable equivalent of "application scope" in coldfusion. need able access variables in several mxml files , not want have create separate events each type need access.

is possible? not talking not using events @ data binding ect. speaking in terms of variables set right when application instantiates , not change after that.

any ideas helpful! thanks!


try defining class (as or mxml), , define static properties. these can accessed anywhere, anytime. example:

public class mysettings {
public static var age:int = 34;
public static var name:string;
}

then anywhere in application,
trace(mysettings.age);

or
mysettings.name = "tim";
trace(mysettings.name);

depending on you're using for, may choose rather use gof singleton pattern:

public class settings {
private var singleton:settings;
public function instance():settings{
if (!singleton) singleton = new settings();
return singleton;
}

then make settings instance properties of settings class. when want use it, can

settings.instance.name

or

private var mysettings:settings = settings.instance;
trace(mysettings.name);


More discussions in Flex (Read Only)


adobe

Comments

Popular posts from this blog

Thread: PKI Client 5.00 install (for eToken Pro)

ATmega2560-Arduino Pin Mapping

Crossfader Arduino Tutorial