1 Reply Latest reply on Oct 4, 2010 12:39 AM by Anitha Selvaraj

    Passing data from one state to another state

    YuHsin4221123 Level 1

      Hi, I'm facing problem with this. I tried this very simple method for passing my data from state1 to state2, but this problem keeps occuring when i start clicking on a button

       

      Here is my code.

      ---- MyProject.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:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
                     xmlns:components="components.*">
          <s:layout>
              <s:BasicLayout/>
          </s:layout>
          <s:states>
              <s:State name="Home"/>
              <s:State name="Searched"/>
          </s:states>
          <mx:Image source="../images/background.jpg" x="0" y="0" includeIn="Home"/>
          <s:TextInput x="206" y="361" width="464" id="searchTextInput" includeIn="Home"/>
          <components:retrieveSearch includeIn="Searched" x="258" y="147" id="searchpage" search="{searchTextInput.text}">
          </components:retrieveSearch>
          <s:Button x="691" y="361" label="Search" color="#46AE32" id="searchButton" includeIn="Home" click="searchpage.showresultText.text=searchpage.getResult()"/>

       

      </s:Application>

       

      --------------------------

       

      ---- retrieveSearch.mxml -----

       

      <?xml version="1.0" encoding="utf-8"?>
      <s:Panel xmlns:fx="http://ns.adobe.com/mxml/2009"
               xmlns:s="library://ns.adobe.com/flex/spark"
               xmlns:mx="library://ns.adobe.com/flex/mx" width="400" height="300" skinClass="spark.skins.spark.PanelSkin" title="Your searched term">
          <fx:Declarations>
              <!-- Place non-visual elements (e.g., services, value objects) here -->
          </fx:Declarations>
          <fx:Script>
              <![CDATA[
                  [Bindable]
                  public var search:String;
                  public function getResult():String
                  {
                      return "You searched for: " +search;
                  }
              ]]>
          </fx:Script>
         
          <s:Label x="56" y="119" id="showresultText" fontSize="36"/>
         
      </s:Panel>

       

      ----------------------------------------------

       

      Thank you

        • 1. Re: Passing data from one state to another state
          Anitha Selvaraj Level 2

          Hi,

           

          Change the MyProject.mxml to the following code and check.

           

           

          <?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:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600"
                         xmlns:components="components.*">
              <s:layout>
                  <s:BasicLayout/>
              </s:layout>
              <s:states>
                  <s:State name="Home"/>
                  <s:State name="Searched"/>
              </s:states>
              <fx:Script>
                  <![CDATA[
                      private function changeState():void {
                          this.currentState = "Searched";
                          searchpage.showresultText.text=searchpage.getResult();
                      }
                  ]]>
              </fx:Script>
              <mx:Image source="../images/background.jpg" x="0" y="0" includeIn="Home"/>
              <s:TextInput x="206" y="361" width="464" id="searchTextInput" includeIn="Home"/>
              <components:retrieveSearch includeIn="Searched" x="258" y="147" id="searchpage" search="{searchTextInput.text}">
              </components:retrieveSearch>
              <s:Button x="691" y="361" label="Search" color="#46AE32" id="searchButton" includeIn="Home" click="changeState()"/>
               
             
          </s:Application>

           

          Regards,

          Anitha