When one starts coding in flex the common question rises in mind is that ‘how can i accecss the varibles from different scopes of the application?’
Ok. Let learn some basic application scope in flex
The highest level root application object for a Flex application. This can be used to access the root application object regardless of where you are within a component or sub-application. It can be referenced via the fully qualified name, or in cases where you will use it multiple times, import mx.core.Application and use Application.application to reference the root app variables or methods. For instance:
<mx:Script><![CDATA[ import mx.core.Application;]]></mx:Script><mx:Button label=”Say Hello” click=”Application.application.sayHello();”/>
where sayHello() is defined in your root application code… this property is especially useful for your projects where you have custom components or classes that need to access a shared set of data that is defined in the root.
A property you access within your AIR app that retrieves properties specific to that AIR application. For instance, it can be used to get at properties such as the application descriptor, the publisher of the AIR app, main application icon or menu. You would also use this Singleton object to add event listeners for actions specific to the AIR app, such as the app exiting (NativeApplication.nativeApplication.addEventListener(Event.EXITING, onExiting);).
The outerDocument property is used to access functions and properties defined in your main MXML file when the scope within your code block might have changed, such as when using the <mx:Component> tag . The Component object causes the MXML within it to be treated with a new document scope, so while it may seem you can access your functions defined in your main MXML file normally, you will not be able to unless you prefix it with the word outerDocument such as in the following code excerpt. Without this keyword, you will receive a compiler error stating ‘Call to a possibly undefined method <methodName>’
This property can be used to access the application object containing the enclosed object. This could be the top-level application object, but in the case where an application loaded another via the SWFLoader, it will be the currently enclosing application object. An application’s
parentApplication will either be the application object that loaded it, or null if it is the top-level app.
The parent document object for the given Flex application, MXML component or AS component, and only valued when
isDocument() is true. The top-level application will have a
parentDocument of null.
Parent is used specifically for
classes or those extending from them to indicate the parent container or component for this
. The parent object type is always a
This is the core class of an AIR app, and the object you are using when specifying ‘this’ in your AIR app. It implements
as well as extending the
class, so it serves two purposes, essentially wrapping the initial
objects. One big thing to note here, is that only events from the inherent
are dispatched from the root
object, which differs from a browser application which dispatches events for ALL windows associated with that root
. This is an important distinction to be wary of when developing multi-windowed applications