Scoping in ActionScript is largely a description of what the this keyword refers to at any given point. ActionScript lets you pass functions and call those functions using different scopes, so the this keyword can refer to different objects at different times. In general, an object's methods execute within the context of the object and not the calling object.
In your application's core MXML file, you can access the Application object using the this keyword. However, in custom ActionScript and MXML components, event handler objects, or external ActionScript class files, Flex executes in the context of those objects and classes, and the this keyword refers to the current scope and not the Application scope.
You can access the parent Document and Application objects using the following methods:
parentDocument, parentApplication, or Application.application properties.
Flex includes an Application.application property that you can use to access the root application. In addition, you can use the parentDocument property to access the next level up in the document chain of a Flex application, or the parentApplication property to access the next level up in the application chain.
Scoping in event handlers can be confusing. Event handlers that are declared as objects execute in their own scope and not in the scope of the object that triggered the event or the application. As a result, you can use the Delegate class to pass a reference to the proper scope when defining an event handler.
The following sections discuss function scope, variable scope, reserved words, the this keyword, and using the Application.application, parentApplication, and parentDocument properties to access scopes outside of the current context. For more information about event handler scoping, see Scoping in event handlers.
Version 1.5
Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/flex/15/flex_docs_en/00002174.htm