In this example, you propagate the event to the calling file. You could, alternatively, create an
event type and new event object as part the propagation. For more information on the
metadata tag, see
[Event]
page
45.
You can handle the
close
<?xml version="1.0"?>
<!-- mxmlAdvanced/MainAddressFormHandleEvent.mxml -->
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
xmlns:MyComp="myComponents.*">
<mx:Script>
<![CDATA[
import flash.events.Event;
private function handleCloseEvent(eventObj:Event):void {
myTAClose.text=eventObj.type;
}
private function handleMouseDown(eventObj:Event):void {
myTA.text=eventObj.type;
}
]]>
</mx:Script>
<mx:TextArea id="myTA" />
<mx:TextArea id="myTAClose" />
<MyComp:AddressForm mouseDown="handleMouseDown(event);"
close="handleCloseEvent(event);"/>
</mx:Application>
About interfaces
Interfaces are a type of class that you design to act as an outline for your components. When
you write an interface, you provide only the names of public methods rather than any
implementation. For example, if you define two methods in an interface and then implement
that interface, the implementing class must provide implementations of those two methods.
Interfaces in ActionScript can only declare methods and properties by using setter and getter
methods; they cannot specify constants. The benefit of interfaces is that you can define a
contract that all classes that implement that interface must follow. Also, if your class
implements an interface, instances of that class can also be cast to that interface.
114
Creating Advanced MXML Components
Chapter 5, "Using Metadata Tags in Custom Components," on
event in your main application, as the following example shows: