0 Replies Latest reply on Sep 15, 2010 1:40 AM by flatrón

    States/Components

    flatrón

      Hi, there:

       

      I am just beginner (also in this forum), and I need some help about Flex 3 developing.

       

      I am trying to develope a Flex 3 app.

       

      The app reads data from a xml file.

      Then app shows data that has been read.

      Then the user selects an element by clicking it.

      Then a component is shown based on the element the user clicks.

       

      I have developed this using states and components.

      Every element of the data shown, has a particular field that stores the name of the state, which is the same than the name of the component to be shown.

       

      The question is:

       

      How could I optimize source code by using any special syntax (maybe actionscript) in order to just write down one "variable" state with its "variable" component, knowing that both relates to a single file field?

       

      Here is some example source:

       

      .XML file

       

      <root>

       

      <motorbike>

       

      <make>Benelli</make>

       

      <volume>250</volume>

       

      <model>250-2C</model>

       

      <year>1974</year>

       

      <type>Road</type>

       

      <file_Name>Benelli_250_2C_1974</file_Name>

       

      <img_Name>Benelli/250/2-C/1974/thumb.jpg</img_Name>

       

      </motorbike>

       

      <motorbike>

       

      <make>BMW</make>

       

      <volume>750</volume>

       

      <model>R75-6</model>

       

      <year>1975</year>

       

      <type>Road</type>

       

      <file_Name>BMW_R75_6_1975</file_Name>

       

      <img_Name>BMW/750/R75-6/1975/thumb.jpg</img_Name>

       

      </motorbike>

       

      <motorbike>

       

      <make>Benelli</make>

       

      <volume>250</volume>

       

      <model>250-2C</model>

       

      <year>1974</year>

       

      <type>Road</type>

       

      <file_Name>Benelli_250_2C_1974</file_Name>

       

      <img_Name>Benelli/250/2-C/1974/thumb.jpg</img_Name>

       

      </motorbike>

       

      <motorbike>

       

      <make>BMW</make>

       

      <volume>750</volume>

       

      <model>R75-6</model>

       

      <year>1975</year>

       

      <type>Road</type>

       

      <file_Name>BMW_R75_6_1975</file_Name>

       

      <img_Name>BMW/750/R75-6/1975/thumb.jpg</img_Name>

       

      </motorbike>

      <motorbike>

       

      <make>Benelli</make>

       

      <volume>250</volume>

       

      <model>250-2C</model>

       

      <year>1974</year>

       

      <type>Road</type>

       

      <file_Name>Benelli_250_2C_1974</file_Name>

       

      <img_Name>Benelli/250/2-C/1974/thumb.jpg</img_Name>

       

      </motorbike>

       

      <motorbike>

       

      <make>BMW</make>

       

      <volume>750</volume>

       

      <model>R75-6</model>

       

      <year>1975</year>

       

      <type>Road</type>

       

      <file_Name>BMW_R75_6_1975</file_Name>

       

      <img_Name>BMW/750/R75-6/1975/thumb.jpg</img_Name>

       

      </motorbike>

       

      </root>

       

      Then the .MXML file:

       

       

       

      <mx:states>

       

       

      <mx:State name="Benelli_250_2C_1974">

       

       

      <mx:RemoveChild target="{tlMotorbikes}" />

       

       

      <mx:AddChild relativeTo="{appCtrlBar}" position="lastChild">

       

       

      <mx:Label height="35" width="100%" y="100" text="{tlMotorbikes.selectedItem.make} {tlMotorbikes.selectedItem.model} ({tlMotorbikes.selectedItem.year})" fontWeight="bold" fontSize="24" />

       

       

      </mx:AddChild>

       

       

      <mx:AddChild relativeTo="{pnl}" position="lastChild">

       

       

      <v:Benelli_250_2C_1974 />

       

       

      </mx:AddChild>

       

      <mx:SetProperty target="{btnOtro}" name="visible" value="true" />

       

      <mx:SetProperty target="{lblSearch}" name="visible" value="false" />

       

      <mx:SetProperty target="{search}" name="visible" value="false" />

       

      </mx:State>

       

      <mx:State name="BMW_R75_6_1975">

       

      <mx:RemoveChild target="{tlMotorbikes}" />

       

      <mx:AddChild relativeTo="{appCtrlBar}" position="lastChild">

       

      <mx:Label height="35" width="100%" y="100" text="{tlMotorbikes.selectedItem.make} {tlMotorbikes.selectedItem.model} ({tlMotorbikes.selectedItem.year})" fontWeight="bold" fontSize="24" />

       

      </mx:AddChild>

       

      <mx:AddChild relativeTo="{pnl}" position="lastChild">

       

      <v:BMW_R75_6_1975 />

       

      </mx:AddChild>

       

      <mx:SetProperty target="{btnOtro}" name="visible" value="true" />

       

      <mx:SetProperty target="{lblSearch}" name="visible" value="false" />

       

      <mx:SetProperty target="{search}" name="visible" value="false" />

       

      </mx:State>

       

      </states>

       

      Thank you in advance.