User Guide
116 Creating Advanced MXML Components
Methods that are implemented in the custom component must have the same return type as
their corresponding methods in the interface. If no return type is specified in the interface, the
implementing methods can declare any return type.
About implementing IMXMLObject
You cannot define a constructor for an MXML component. If you do, the Flex compiler
issues an error message that specifies that you defined a duplicate function.
For many types of Flex components, you can use an event listener instead of a constructor. For
example, depending on what you want to do, you can write an event listener for the
preinitialize, initialize, or creationComplete event to replace the constructor.
These events are all defined by the UIComponent class, and inherited by all of its subclasses.
If you create an MXML component that is not a subclass of UIComponent, you cannot take
advantage of these events. You can instead implement the IMXMLObject interface in your
MXML component, and then implement the
IMXMLObject.initialized() method, as the
following example shows:
<?xml version="1.0"?>
<!-- mxmlAdvanced/myComponents/ObjectComp.mxml -->
<mx:Object xmlns:mx="http://www.adobe.com/2006/mxml"
implements="mx.core.IMXMLObject">
<mx:Script>
<![CDATA[
// Implement the IMXMLObject.initialized() method.
public function initialized(document:Object, id:String):void {
trace("initialized, x = " + x);
}
]]>
</mx:Script>
<mx:Number id="y"/>
<mx:Number id="z"/>
<mx:Number id="x"/>
</mx:Object>