Architecting an Application with MXML Components

Base on the Total Tainining Flex 2 video presented by James Talbot.

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.

<?xml version="1.0" encoding="utf-8"?>
<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.

<?xml version="1.0" encoding="utf-8"?>
<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.

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
   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

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
   layout="vertical"
   backgroundColor="white"
   xmlns:comp="components.*">

Here is the whole process starting with the application file.

<?xml version="1.0" encoding="utf-8"?>
<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.

<?xml version="1.0" encoding="utf-8"?>
<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.

Comments
Cartier replica Watches's Gravatar ift Some <b><a href="http://www.discountwatchmvp.com">rolex watches</a></b> simple checks can quickly <b><a href="http://www.discountwatchmvp.com">buy rolex watches</a></b> identify fraudulent websites. A <b><a href="http://www.discountwatchmvp.com">rolex watches</a></b> few examples of these <b><a href="http://www.discountwatchmvp.com">rolex watches</a></b> fake Rolex watches will <b><a href="http://www.discountwatchmvp.com">lady rolex watches</a></b> be ones like a <b><a href="http://www.discountwatchmvp.com">rolex watches</a></b> ladies watch. You can <b><a href="http://www.discountwatchmvp.com">rolex watches</a></b> find different watches which <b><a href="http://www.discountwatchmvp.com">rolex watches</a></b> features the inner workings <b><a href="http://www.discountwatchmvp.com">gucciwatches</a></b> of the watch to <b><a href="http://www.discountwatchmvp.com">rolex watches</a></b> one side of the clock face. You will also find pocket watches which have a fu
# Posted By Cartier replica Watches | 7/11/10 9:01 PM
Cartier replica Watches's Gravatar its [b][url=http://www.discountwatchmvp.com]rolex watches[/url][/b] presence felt regardless of [b][url=http://www.discountwatchmvp.com]new rolex watches[/url][/b] who wears it. BBB [b][url=http://www.discountwatchmvp.com]imitation rolex watches[/url][/b] Logo If the original [b][url=http://www.discountwatchmvp.com]rolex watches[/url][/b] company has released a [b][url=http://www.discountwatchmvp.com]discount rolex watches[/url][/b] new model, just be [b][url=http://www.discountwatchmvp.com]rolex watches[/url][/b] patient for a few [b][url=http://www.discountwatchmvp.com]rolex watches[/url][/b] weeks for the Swiss [b][url=http://www.discountwatchmvp.com]knock off rolex watches[/url][/b] fake watches to surface [b][url=http://www.discountwatchmvp.com]rolex watches[/url][/b] up in the markets. [b][url=http://www.discountwatchmvp.com]rolex watches[/url][/b] If the original has some changes made to it, it will not be long before the Swiss fake watches also incor
# Posted By Cartier replica Watches | 7/11/10 9:02 PM
BloggArt  |  Portfolio  |  Contact          BloggArt is running BlogCFC version 5.5.