Oh, what the heck.  I might as well post an example how to control
the currentState of components with the modelLocator.  Hopfully, no-
one is offended by the simplicity.

Tim Hoff

//*******************************************************************
  ModelLocator
//*******************************************************************

package code.model
{
      import org.nevis.cairngorm.model.ModelLocator;
     
      [Bindable]
      public class ModelLocator implements
org.nevis.cairngorm.model.ModelLocator
      {           
            private static var
modelLocator:code.model.ModelLocator;
           
            public static function getInstance() :
code.model.ModelLocator
            {
                  if ( modelLocator == null )
                        modelLocator = new
code.model.ModelLocator();
                       
                  return modelLocator;
         }
        
//-------------------------------------------------------------------

               public function ModelLocator()
               {     
                     if ( code.model.ModelLocator.modelLocator !=
null )
                        throw new Error( "Only one
ModelLocator instance should be instantiated" );     
               }
        
//-------------------------------------------------------------------
                                               
            public var mainPanelViewCurrentState : String
= "logo";
            public static const VIEWING_MAIN_LOGO : String
= "logo";
            public static const VIEWING_MAIN_SEARCH : String
= "search";
            public static const VIEWING_MAIN_SEARCHING : String
= "searching";

            public var searchViewCurrentState : String
= "authors";
            public static const VIEWING_SEARCH_AUTHORS : String
= " authors ";
            public static const VIEWING_SEARCH_CONTACTS : String
= "contacts";

      }
     
}


//*******************************************************************
  Component MXML
//*******************************************************************

<?xml version="1.0" encoding="utf-8"?>
<mx:Panel xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*"
    height="100%" width="100%" paddingTop="10"
    horizontalScrollPolicy="off" verticalScrollPolicy="off"
    xmlns:logo="code.view.mainPanel.logo.*"
    xmlns:search="code.view.mainPanel.search.*"
    xmlns:searching="code.view.mainPanel.searching.*"
    currentState="{ ModelLocator.getInstance
().mainPanelViewCurrentState }">

      <mx:Script>
      <![CDATA[
           
            import code.model.ModelLocator;
                                               
     
      ]]>
      </mx:Script>
     
         <mx:Canvas id="mainCanvas" width="100%" height="100%"/>
     
      <mx:states>
            <mx:State name="{ModelLocator.VIEWING_MAIN_LOGO}"
                  id="logo">
                  <mx:AddChild target="{mainCanvas}"
position="lastChild">
                        <logo:LogoView/>
                  </mx:AddChild>
            </mx:State>
            <mx:State name="{ModelLocator.VIEWING_MAIN_SEARCH}"
                  id="search">
                  <mx:AddChild target="{mainCanvas}"
position="lastChild">
                        <search:SearchView currentState="{
ModelLocator.getInstance().searchViewCurrentState }"/>
                  </mx:AddChild>
            </mx:State>
            <mx:State
name="{ModelLocator.VIEWING_MAIN_SEARCHING}"
                  id="searching">
                  <mx:AddChild target="{mainCanvas}"
position="lastChild">
                        <searching:SearchingView/>
                  </mx:AddChild>
            </mx:State>
      </mx:states>
</mx:Panel>

//*******************************************************************
  Command
//*******************************************************************


package code.commands
{
      import org.nevis.cairngorm.commands.Command;
        import org.nevis.cairngorm.control.CairngormEvent;
      import code.model.ModelLocator;
           
      public class sampleCommand implements Command
      {
           
//-------------------------------------------------------------------
     
            public function execute(
cairngormEvent:CairngormEvent ):void
            {          
     
      // Do Something

      ModelLocator.getInstance().mainPanelViewCurrentState =
ModelLocator.VIEWING_MAIN_SEARCH;
            }
           
      }
}







--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com




YAHOO! GROUPS LINKS




Reply via email to