5 Replies Latest reply on Nov 20, 2009 11:53 AM by Bhulka

    data sharing between states

    Bhulka

      Hello All,

       

      I am developing this application where first page is search page which has option of searching for PO number. What I don't understand is when I search for example with PO number = 12345, on very next state it will display me the results of search; with the result I also want to display the PO number I searched for means the text input that I entered in my previous page. I don't understand that how come I can get the text input of my first page displayed on my second page. I would like to have heading of secong page something like "Search Results of PO number 12345"

       

      Please help and let me know if I have confused you with anything here. Thanks.

        • 1. Re: data sharing between states
          Gregory Lafrance Level 6

          If this post answers your question or helps, please mark it as such.

           

          I think you are better off not using states and use ViewStack:

           

           

          <?xml version="1.0" encoding="utf-8"?>
          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
            <mx:Script>
              <![CDATA[
                [Bindable] private var poEntered:Boolean = false;
                [Bindable] private var currPO:String;
                
                private function checkData():void{
                  if(poTxt.text == ""){
                    poEntered = false;
                  }else{
                    poEntered = true;
                    currPO = poTxt.text;
                  }
                }
                
                private function resetSearch():void{
                  vs.selectedIndex=0;
                  poTxt.text = "";
                }
              ]]>
            </mx:Script>
            <mx:ViewStack id="vs">
              <mx:VBox label="Search Page">
                <mx:Label text="Enter PO#:"/>
                <mx:TextInput id="poTxt" change="checkData();"/>
                <mx:Button label="Search" enabled="{poEntered}" click="vs.selectedIndex=1"/>
              </mx:VBox>
              <mx:VBox>
                <mx:Label id="lbl" text="Results Page for {currPO}"/>
                <mx:Button label="Search Again" click="resetSearch();"/>
              </mx:VBox>
            </mx:ViewStack>
          </mx:Application>
          
          • 2. Re: data sharing between states
            Bhulka Level 1

            Greg,

             

            This helps as far as my knowledge is concerned but this application is designed using states. I don't think at this point I am able to change the application and make it as to use viewstack. It would be really helpful if the similar solution you can provide me using states.

            • 3. Re: data sharing between states
              Gregory Lafrance Level 6

              If this post answers your question or helps, please mark it as such.

               

              Here is an example using states:

               

               

              <?xml version="1.0" encoding="utf-8"?>
              <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
                <mx:Script>
                  <![CDATA[
                    [Bindable] private var poEntered:Boolean = false;
                    [Bindable] private var currPO:String;
                    
                    private function checkData():void{
                      if(poTxt.text == ""){
                        poEntered = false;
                      }else{
                        poEntered = true;
                        currPO = poTxt.text;
                      }
                    }
                    
                    private function resetSearch():void{
                      this.currentState="";
                      poTxt.text = "";
                      poEntered = false;
                    }
                  ]]>
                </mx:Script>
                <mx:states>
                  <mx:State name="searchResults">
                    <mx:SetProperty target="{titleLbl}" name="text" value="Search Results"/>
                    <mx:RemoveChild target="{poLbl}"/>
                    <mx:RemoveChild target="{poTxt}"/>
                    <mx:RemoveChild target="{searchBtn}"/>
                    <mx:AddChild>
                      <mx:Label id="lbl" text="Results Page for {currPO}"/>        
                    </mx:AddChild>
                    <mx:AddChild>
                      <mx:Button label="Search Again" click="resetSearch();"/>              
                    </mx:AddChild>  
                  </mx:State>
                </mx:states>
                <mx:Label id="titleLbl" text="Search Page" fontSize="14"/>
                <mx:Label id="poLbl" text="Enter PO#:"/>
                <mx:TextInput id="poTxt" change="checkData();"/>
                <mx:Button id="searchBtn" label="Search" enabled="{poEntered}" click="this.currentState='searchResults'"/>
              </mx:Application>
              
              • 4. Re: data sharing between states
                Bhulka Level 1

                Wonderful Greg....I really appreciate your quick help, It was right on time when I needed most...truely appreciated!!!

                • 5. Re: data sharing between states
                  Bhulka Level 1

                  Hey Greg,

                   

                  I implemented the solution you provided into my app and it worked fine. However, I am facing a issue with the position of "Results of PO 12345"..what happens is once I get on to the search result page, and when scroll down the page this heading "Results of PO 12345" goes with the scroll and moving its position with scroll. It means it is coming on the actual results/contents of that page. it has to be at one position and should not move at all as other titles. Any idea for this???