Yeah,

That is a very good pattern for Flex mxml.

Thanks, Mike

On 4/21/06, Tim Hoff <[EMAIL PROTECTED]> wrote:

This version should be easier to read (with a magnifying glass :).  Remember to register the command in the FrontController and dispatch the commands' event somewhere. 

Cheers,

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";  // Default

                                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";   // Default

                                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 getContactsCommand implements Command

                {

                               

//-------------------------------------------------------------------

               

                                public function execute( cairngormEvent:CairngormEvent ):void

                                {        

                                             // Get Data or Do Something;

 

                                           // Change currentState of mainPanel and search Views;                           

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

                                            ModelLocator.getInstance ().searchViewCurrentState = ModelLocator.VIEWING_SEARCH_CONTACTS;

                                }                              

                }

}



--
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






--
What goes up, does come down.

--
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