1 Reply Latest reply on Oct 22, 2009 10:04 AM by tori0915

    How can i change currentstate from the button of the custum component?

    tori0915 Level 1

      Hi! Please give me your advice!!

       

      I want to control the currentstate from the button of the custum component.

       

      The construction of mxmls as follows;

       

      main.mxml > states(login,mainframe)

          - login.mxml

          - mainframe.mxml > states(menu,page1,page2...)

                - menu.mxml

                - page1.mxml

                - page2.mxml

       

      >> main(login) --> main(mainframe(menu))

          1. click the loginbutton of login.mxml

          2. parentApplication.currentState = "mainframe";

          [result] success!!

       

      >> main(mainframe(menu)) --> main(mainframe(page1))

          1. click the toPage1button of menu.mxml

          2. How can I change the currentstate of mainframe.mxml??

       

      each mxml files as follows;

       

      [main.mxml]

      <?xml version="1.0" encoding="utf-8"?>
      <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
            xmlns:s="library://ns.adobe.com/flex/spark"
            xmlns:co="commons.*"
            xmlns:mx="library://ns.adobe.com/flex/halo"
            xmlns:components="components.*"
            width="100%" height="100%" currentState="MainFrame">

      <s:states>
        <s:State name="Login" />
        <s:State name="MainFrame" />
      </s:states>

      <components:login id="loginView" width="100%" height="100%" includeIn="Login"/>
      <components:mainFrame id="mainView" width="100%" height="100%" includeIn="MainFrame"/>
      </s:Application>

       

      [login.mxml]

      <?xml version="1.0" encoding="utf-8"?>
      <s:Group xmlns:fx="http://ns.adobe.com/mxml/2009"
        xmlns:s="library://ns.adobe.com/flex/spark"
        xmlns:mx="library://ns.adobe.com/flex/halo"
        xmlns:components="components.*"
        width="100%" height="100%" baseColor="#CCCCCC">
      <fx:Script>
        <![CDATA[
        import mx.core.UIComponent;
       
        protected function login_clickHandler(event:MouseEvent):void
        {
            parentApplication.currentState = "MainFrame";

        }
       
        ]]>
      </fx:Script>

       

      <s:Panel title="Login"
          textAlign="center"
          color="#C00000" baseColor="#DDD9C3" borderColor="#A6A6A6"
          x="250" y="100" height="150">
        <s:Label x="23" y="23" text="ID" color="#000000" fontWeight="bold"/>
        <s:Label x="23" y="55" text="Password" color="#000000" fontWeight="bold"/>
        <s:TextInput x="91" y="18"/>
        <s:TextInput x="91" y="48"/>
        <s:Button x="64" y="84" label="Login" color="#297083" baseColor="#CCCCCC" width="150" enabled="true" click="login_clickHandler(event)"/>
      </s:Panel>


      </s:Group>


      [mainframe.mxml]

      <?xml version="1.0" encoding="utf-8"?>
      <s:Group xmlns:fx="http://ns.adobe.com/mxml/2009"
         xmlns:s="library://ns.adobe.com/flex/spark"
         xmlns:mx="library://ns.adobe.com/flex/halo"
         xmlns:components="components.*"
         xmlns:workflow="components.workflow.*"
         xmlns:common="components.common.*"
         name = "MainFrame"
         currentState="Menu">
        
      <s:states>
        <s:State name="Menu" />
        <s:State name="Page1" />
      </s:states>

      <!-- HEADER AREA -->
      <s:Group id="header" height="20">
        <mx:HBox width="940" height="20" backgroundColor="#a6a6a6" verticalAlign="middle" borderVisible="false">
         <mx:Label text="Header(temp)" left="20" color="#000000" paddingLeft="5"/>
        </mx:HBox>
      </s:Group>

      <!-- BODY AREA -->
      <s:Group id="body" y="20">
        <components:mainMenu id="mainMenuView" width="100%" height="100%" includeIn="Menu" />
        <workflow:page1 id="page1View" width="100%" height="100%" includeIn="Page1" />
      </s:Group>

      <!-- FOOTER AREA -->
      <s:Group id="footer" height="20" y="500">
        <mx:HBox width="940" height="20" backgroundColor="#a6a6a6" verticalAlign="middle" borderVisible="false">
         <mx:Label text="Footer(temp)" left="20" color="#000000" paddingLeft="5"/>
        </mx:HBox>
      </s:Group>
      </s:Group>

      [mainMenu.mxml]

      <?xml version="1.0" encoding="utf-8"?>
      <s:Group xmlns:fx="http://ns.adobe.com/mxml/2009"
           xmlns:s="library://ns.adobe.com/flex/spark"
           xmlns:mx="library://ns.adobe.com/flex/halo"
           xmlns:components="components.*"
           xmlns:common="components.common.*"
           width="100%" height="100%" baseColor="#CCCCCC"
           name="mainMenu">

      <fx:Script>
        <![CDATA[
         import components.workflow.wf_top;
        
         /* 画面の切り替え */
        
         // ワークフロートップへ
         protected function toWorkflow_clickHandler(event:MouseEvent):void
         {

                ????????????????????????

         }
        ]]>
      </fx:Script>

        <s:Button x="120" y="85" label="ワークフロー管理へ" color="#297083" fontFamily="MS ゴシック" fontWeight="normal" textAlign="center" width="170" fontSize="14" enabled="true" id="toWorkflow" click="toWorkflow_clickHandler(event)"/>
        <s:Button x="120" y="85" label="作業履歴管理へ" color="#297083" fontFamily="MS ゴシック" fontWeight="normal" textAlign="center" width="170" fontSize="14"/>

      </s:Group>

       

      Thanks,

        • 1. Re: How can i change currentstate from the button of the custum component?
          tori0915 Level 1

          Sorry!!

           

          I miss mainmenu.mxml

           

          mainmenu.mxml as follows;

           

          [mainMenu.mxml]

          <?xml version="1.0" encoding="utf-8"?>
          <s:Group xmlns:fx="http://ns.adobe.com/mxml/2009"
               xmlns:s="library://ns.adobe.com/flex/spark"
               xmlns:mx="library://ns.adobe.com/flex/halo"
               xmlns:components="components.*"
               xmlns:common="components.common.*"
               width="100%" height="100%" baseColor="#CCCCCC"
               name="mainMenu">

          <fx:Script>
            <![CDATA[
            
             protected function toPage1_clickHandler(event:MouseEvent):void
             {

               ???????????????????????????????????????

             }
            ]]>
          </fx:Script>

            <s:Button x="120" y="85" label="Page1" color="#297083" fontWeight="normal" textAlign="center" width="170" fontSize="14" enabled="true" id="toPage1" click="toPage1_clickHandler(event)"/>
            <s:Button x="120" y="85" label="Page2" color="#297083" fontWeight="normal" textAlign="center" width="170" fontSize="14"/>

          </s:Group>