To reference the application object inside another object (either UI or otherwise) just define a variable to reference "Applicaton.application";

Note that this returns an object - not an instance of Application per se.

One interesting note is that singletons can be instantiated through using a check in the following manner...

var _x:Object = Application.application;
if (_x["mySingleton"] == null) {
        _x["mySingleton"] = new SingletonClass();
}
return _x["mySingleton"] as SingletonClass;

Maybe that helps someone ;)

Samuel


On Jan 11, 2009, at 1:32 PM, Manish Jethani wrote:

On 1/10/09, dorkie dork from dorktown <dorkiedorkfromdorkt...@gmail.com > wrote:

> I have a class on the application like this:
>
> <managers:MyClass />
>
> How do I find out inside that class in the constructor if that class is on the Application?

By "Application" I assume the Flex application (instance of
mx.core.Application). The only way to do this is to walk the parent
chain (parent.parent.parent....) until you come across an Application
instance, or null.

inApplication = false;
p = this.parent;

while (p != null) {
if (p is Application) {
inApplication = true;
break;
}

p = p.parent;
}

Your loop will never run, however, since parent will always be null in
the constructor.

Note that checking for Application is different from checking for
stage. The Application may not have been added to the stage when
you're doing this check (even if not in the constructor). So if you
want to check if you're on the stage yet, just check for the stage
property.

onStage = (stage != null);

Manish

--
http://manishjethani.com



Reply via email to