3 Replies Latest reply on Feb 26, 2007 6:01 PM by ringx007

    question about 'currentState'

    newhander
      2 mxml files
      ==================================================
      index.mxml

      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" xmlns:ns1="*" >
      <mx:Script>
      <![CDATA[
      private function login():void{
      this.currentState = 'main';
      }
      ]]>
      </mx:Script>
      <mx:Button id="btnLogin" label="Sign in" click="login()" />
      <mx:states>
      <mx:State name="main">
      <mx:RemoveChild target="{btnLogin}"/>
      <mx:AddChild position="lastChild">
      <ns1:main width="100%"></ns1:main>
      </mx:AddChild>
      </mx:State>
      </mx:states>

      </mx:Application>

      ===========
      main.mxml

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Module xmlns:mx=" http://www.adobe.com/2006/mxml" >
      <mx:Script>
      <![CDATA[
      private function goback():void{
      this.currentState = '';
      }
      ]]>
      </mx:Script>
      <mx:Button click="goback()" cornerRadius="0"/>
      </mx:Module >
      ===========
      How to go back the index.mxml when I click the button of main.mxml?

      seems this line doesnt play a role:
      this.currentState = '';


      Thx a lot !
        • 1. question about 'currentState'
          ringx007
          try:
          parent["currentState"] = '';
          or
          Application.application["currentState"] = '';
          • 2. Re: question about 'currentState'
            newhander Level 1
            thx!
            parent["currentState"] = '';
            works fine!

            why parent["currentState"] not parent.currentState?
            seems parent object doesnt have this property...
            • 3. Re: question about 'currentState'
              ringx007 Level 1
              Because type of parent is definded as "DisplayObjectContainer", "DisplayObjectContainer" doesn't have this property, but actually parent is "Application " here(DisplayObjectContainer is supper class of Application), so parent has "currentState", but "parent.currentState" will get compile error.
              it can be:
              UIComponent(parent).currentState = '';

              but i think the second way:Application.application["currentState"] = '' is better,
              if you add the "main" on a Container, the parent will not the application but this Container.

              if(Application.application && (Application.application is UIComponent)){
              UIComponent(Application.application).currentState = "":
              }