3 Replies Latest reply on Oct 12, 2010 1:46 AM by YuHsin4221123

    Problem with states and component in flex

    YuHsin4221123 Level 1

      I am trying to build this flex application like this

       

      ExpertDiscoverySystem.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="1280" minHeight="960" xmlns:component="component.*" currentState="SearchStart">
          <s:layout>
              <s:BasicLayout/>
          </s:layout>
          <s:states>
              <s:State name="SearchName"/>
              <s:State name="SearchDomain"/>
              <s:State name="SearchResult"/>
              <s:State name="SearchStart"/>
          </s:states>
          <fx:Declarations>
              <!-- Place non-visual elements (e.g., services, value objects) here -->
          </fx:Declarations>
         
          <!--<fx:Script>
              <![CDATA[
                  private function changeState():void {
                      this.currentState = "SearchResult";
                      searchpage.searchTerm.text=searchpage.getResult();
                  }
              ]]>
          </fx:Script>-->
         
          <mx:Image x="0" y="0" source="../image/background.jpg" includeIn="SearchDomain,SearchName,SearchStart"/>
          <!--<s:TextInput x="120.65" y="507.8" width="806" id="searchText" includeIn="SearchDomain,SearchName"/>
          <s:Button x="951" y="508" label="Search this!" id="searchButton" includeIn="SearchDomain,SearchName" click=""/>-->
          <mx:LinkButton label="Name" fontSize="36" fontFamily="Verdana" includeIn="SearchStart" click="currentState='SearchName' " color="#CE1717" enabled="true" x="383" y="556" fontWeight="bold"/>
          <mx:LinkButton fontSize="36" fontFamily="Verdana" click="currentState='SearchDomain'" includeIn="SearchStart" color="#CC1C1C" label="Domain" x="656" y="555" fontWeight="bold"/>
          <mx:Image includeIn="SearchResult" x="0" y="0" source="../image/backgroundsearch.jpg"/>
          <s:TextInput includeIn="SearchResult" x="542.1" y="47.6" width="576"/>
          <s:Button includeIn="SearchResult" x="1132" y="47.1" label="Search" id="Search2Button"/>
          <component:search includeIn="SearchDomain" x="250" y="420">
          </component:search>
          <component:searchResult includeIn="SearchResult" id="searchpage" x="29" y="115">
          </component:searchResult>
          <component:search includeIn="SearchName" x="250" y="420">
          </component:search>
         
      </s:Application>

       

      and the component

      search.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/mx" width="800" height="400" contentBackgroundAlpha="0.0" xmlns:component="component.*">
          <s:layout>
              <s:BasicLayout/>
          </s:layout>
         
          <fx:Declarations>
              <!-- Place non-visual elements (e.g., services, value objects) here -->
              <component:searchResult id="searchpage" searchedTerm="{searchTextInput.text}">
              </component:searchResult>
          </fx:Declarations>
          <fx:Script>
              <![CDATA[
                  private function changeState():void {
                      this.currentState = "SearchResult";
                      searchpage.searchTerm.text = searchpage.getResult();
                  }
              ]]>
          </fx:Script>
         
          <s:TextInput width="572" id="searchTextInput"  x="49" y="83"/>
         
          <s:Button label="Search this!" id="searchButton"  click="changeState()" x="652" y="84"/>
      </s:Group>

       

      and searchResult.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/mx" width="900" height="800">
          <fx:Declarations>
              <!-- Place non-visual elements (e.g., services, value objects) here -->
          </fx:Declarations>
         
          <fx:Script>
              <![CDATA[
                  [Bindable]
                  public var searchedTerm:String;
                  //public var searchCriteria:String;
                  public function getResult():String
                  {
                      return searchedTerm;
                  }
              ]]>
          </fx:Script>
          <s:Label x="6" y="13" text="You've searched for:" fontSize="18"/>
          <s:Label x="173" y="13" fontSize="18" id="searchTerm" color="#FF0000"/>
         
      </s:Group>

       

      The problems goes like this. I need to access to the state "SearchResult" at my main mxml application from my component search.mxml, with my currrent code it is impossible to access it at all because the state "SearchResult" wasn't include at the component search.mxml

       

      Is there anyway to access into the state from my main application from my component?