1 Reply Latest reply on Mar 21, 2010 3:22 PM by AdrianWiecek

    How to run functions when changing states?

    AtomicRussian

      Hi everybody

       

      I want to run function when changin states

       

      For example I change my state and write something on Panels title and when this state appears i want to read my title and to do smth

      How can I do it. Where is my mistake?

       

       

      <?xml version="1.0" encoding="utf-8"?>
      <mx:Application
          xmlns:mx="http://www.adobe.com/2006/mxml" verticalAlign="middle"
          width="340" height="250"
          layout="absolute"
      currentStateChange="StateChangez();">


      <mx:Script>
      <![CDATA[
      public function StateChangez():void
      {
      if (currentState=='a')
      {
      //Alert.show('a');
      if (Panel1.title=='New')
      {
      Alert.show('New');
      }
      else
      {
      Alert.show('Edit');
      }

      }
      else
      {
      Alert.show('b');
      }     
      }
      ]]>
      </mx:Script>


      <mx:states>
        <mx:State name="a">
         <mx:RemoveChild target="{button1}"/>
         <mx:RemoveChild target="{button2}"/>
         <mx:AddChild position="lastChild">
          <mx:Panel x="0" y="40" width="340" height="210" layout="absolute" id="Panel1">
          </mx:Panel>
         </mx:AddChild>
         <mx:RemoveChild target="{button3}"/>
        </mx:State>
        <mx:State name="b">
         <mx:RemoveChild target="{button2}"/>
         <mx:RemoveChild target="{button1}"/>
         <mx:RemoveChild target="{button3}"/>
         <mx:AddChild position="lastChild">
          <mx:Label x="10" y="222" text="b"/>
         </mx:AddChild>
        </mx:State>
      </mx:states>
      <mx:Script>
        <![CDATA[
         import mx.controls.Alert;
        ]]>
      </mx:Script>
      <mx:Button label="New" x="10" y="10" id="button1" click="currentState='a';Panel1.title='New';"/>
      <mx:Button x="68" y="10" label="Edit" id="button2" click="currentState='a';Panel1.title='Edit';"/>
      <mx:Button x="10" y="218" label="b" click="currentState='b';" id="button3"/>
      <mx:Button x="265" y="10" label="Read" click="StateChangez()"/>

      </mx:Application>

       

       

       

       

      Message was edited by: AtomicRussian