Architecting an Application with MXML Components
One thing you want to avoid when creating a Flex application is one big long MXML file. Divide the API with separate blocks and managable pieces. All of the components will be initiated within the main mx:Application tag and the component wont have and mx:Application tag.
-File >> New >> MXML Component.
-Enter parent folder.
-File name (name of your component)
-Base on: (select the kind of component to be base on. example VBox, HBox, DataGrid, ect...)
-Click on Finish.
The component will be save in the components folder inside your project.
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml">
Here is the skeleton of the component
</mx:VBox>
Enter component controls to be use in your component, and save the file.
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml">
Note: again you can put anything here. (ex. vBox, Labels, Panels, Datagrids, Variables, ect...)
<mx:Label text="*******Start of component******"/>
<mx:Label text="*******End of component******"/>
</mx:VBox>
Next, Instead of using the name space for all the default component within Flex.
layout="vertical"
backgroundColor="white">
You may want to add a custom name space in the application tag.(xmlns:comp="components.*")
xmlns = Name Space
comp = Sufix name. Any name you like
components.* = import all components in the component folder
layout="vertical"
backgroundColor="white"
xmlns:comp="components.*">
Here is the whole process starting with the application file.
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
layout="vertical"
backgroundColor="white"
xmlns:comp="components.*">
<!--Instatiate the component -->
<comp:PropMethod prop1="My value"/>
</mx:Application>
Here is the component.
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml">
<!--Action Script to be albe to access from out side this component -->
<!--CDATA prevent the XML parsel on getting confuse by any code use in here -->
<!--make it Bidanble -->
<!--make sure to declare the data type property "String" -->
<mx:Script>
<![CDATA[
[Bindable]
public var prop1:String;
]]>
</mx:Script>
<mx:Label text = "{prop1}"/>
</mx:VBox>
This a very simple and powefull proccess to divide and build the application.
