Macromedia flex 2 Manual
Scoping in custom components
83
For example, the following example sets the
horizontalPageScrollSize
property and a
listener for the
scroll
event for your custom control, but you cannot specify properties for
the child
CheckBox
or
TextInput
controls of the Form container:
<?xml version="1.0"?>
<!-- mxml/MainEmptyFormProps.mxml-->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:MyComp="*">
<!-- mxml/MainEmptyFormProps.mxml-->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:MyComp="*">
<mx:Script>
<![CDATA[
import mx.events.ScrollEvent;
<![CDATA[
import mx.events.ScrollEvent;
private function handleScrollEvent(event:ScrollEvent):void {
// Handle scroll event.
}
]]>
</mx:Script>
// Handle scroll event.
}
]]>
</mx:Script>
<MyComp:AddressForm horizontalPageScrollSize="25"
scroll="handleScrollEvent(event);"/>
scroll="handleScrollEvent(event);"/>
</mx:Application>
To configure the children of a custom MXML component, you define new properties in the
MXML component, and then use those new properties to pass configuration information to
the component children. For more information, see
MXML component, and then use those new properties to pass configuration information to
the component children. For more information, see
Scoping in custom components
Scoping is mostly a description of what the
this
keyword refers to at any given point in your
application. In an
<mx:Script>
tag in an MXML file, the
this
keyword always refers to the
current scope. In the main application file, the file that contains the
<mx:Application>
tag,
the current scope is the Application object; therefore, the
this
keyword refers to the
Application object.
In an MXML component, Flex executes in the context of the custom component. The
current scope is defined by the root tag of the file. So, the
current scope is defined by the root tag of the file. So, the
this
keyword refers not to the
Application object, but to the object defined by the root tag of the MXML file.
For more information on scoping, see Chapter 4, “Using ActionScript,” in Flex 2 Developer’s
Guide.
Guide.