Creating custom component involves the use of MXML and some amount of Actionscript too. Now, let us create a ComboBox component that allows the user to choose from True or False. Lets name it BooleanComboBox.
<?xml version="1.0"?>Save this file as BooleanComboBox.mxml. This completes the creation of your custom component using just MXML. As you can see, creating a custom component is not very different from creating an application. The only difference is, the root tag, is not Application, but its ComboBox here. You can change this to the other components to extend them in a similar manner.
<mx:ComboBox xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:dataProvider>
<mx:String>TRUE</mx:String>
<mx:String>FALSE</mx:String>
</mx:dataProvider>
</mx:ComboBox>
Now, to use it in your application, use the following code,
<?xml version="1.0"?>Here, you see that, 'cc' is the namespace to reference your custom component. This is defined in the application tag itself. Then, by using the MXML file's name as the tag name, you are using your custom component in your application.
<mx:application mx="http://www.adobe.com/2006/mxml" cc="*">
<!-- Use the filename as the MXML tag name. -->
<cc:BooleanComboBox/>
</mx:Application>
As simple as that :-)
Next, I will be teaching you, how to create your own custom component using ActionScript. So hang in there !
No comments:
Post a Comment