4 Replies Latest reply on Feb 16, 2012 10:28 PM by havefreetime

    Can I change component's state?

    havefreetime

      Hi All

       

      First of All, I'm sorry for my english. But I'll do my best to explain my question.

       

      Can I change component's state?

       

      For example, When I click the button, I wanna change Label's state.

       

       

      <s:states>

        <s:State name="A"/>

        <s:State name="B"/>

      </s:states>

       

       

      <fx:Script>

        <![CDATA[

            private function changelblState():void{

                 // lbl.includeIn = "B"          --> impossible

         // or

         // lbl.state = "B"                  --> impossible

           }

        ]]>

      </fx:Script>

       

      <mx: Label id="lbl" includeIn="A"/>

      <mx: Button click="changelblState()"/>

       

      How can I change component's state?

       

      Thanks in advance.

       

      Kevin.

        • 1. Re: Can I change component's state?
          Vibhuti Gosavi(InfoCepts)

          Hi ,

           

          You can use currentState property in changelblState() method for changing current state of label.

           

          Please have a look in following link:

           

          http://livedocs.adobe.com/flex/3/html/help.html?content=using_states_4.html

           

            Thanks and Regards,

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

          Vibhuti Gosavi | vgosavi@infocepts.com | www.infocepts.com

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

          1 person found this helpful
          • 2. Re: Can I change component's state?
            havefreetime Level 1

            Thank you for reply.

             

            But I've already tried.

             

             

             

            <s:states>

              <s:State name="A"/>

              <s:State name="B"/>

            </s:states>

             

             

            <fx:Script>

              <![CDATA[

                  private function changelblState():void{

                     lbl.currentState = "B"

                 }

              ]]>

            </fx:Script>

             

            <mx: Label id="lbl" includeIn="A"/>

            <mx: Button click="changelblState()"/>

             

             

             

            I got the error message.

             

            ArgumentError: Undefined state 'invisibleSmallVideo'.

            at mx.core::UIComponent/getState()[E:\dev\4.y\frameworks\projects\framework\src\mx\core\UICo mponent.as:10607]

            at mx.core::UIComponent/findCommonBaseState()[E:\dev\4.y\frameworks\projects\framework\src\m x\core\UIComponent.as:10627]

            at mx.core::UIComponent/commitCurrentState()[E:\dev\4.y\frameworks\projects\framework\src\mx \core\UIComponent.as:10381]

            at mx.core::UIComponent/setCurrentState()[E:\dev\4.y\frameworks\projects\framework\src\mx\co re\UIComponent.as:10323]

            at mx.core::UIComponent/set currentState()[E:\dev\4.y\frameworks\projects\framework\src\mx\core\UIComponent.as:6425]

             

            I know this is fault. If I can use lbl.includeIn = "B";  , I can solve it, but I can't.

            • 3. Re: Can I change component's state?
              supersonicecho Level 2

              Use the currentState property on the parent.

               

              <s:states>

                <s:State name="A"/>

                <s:State name="B"/>

              </s:states>

               

              <s: Label id="lbl" includeIn="A"/>

              <s: Button click=" currentState = 'B' "  />

               

              Piece of unsolicited advice:

              Stop using <mx:> components unless necessary.  Use spark labels and buttons (E.G. <s:Label />, <s:Button/>), especially if you want to use the awesome spark state architecture.

              • 4. Re: Can I change component's state?
                havefreetime Level 1

                Thank you Vibhuti, supersonicecho.

                I did it!

                But I can't understand Child - Parent relationship. It's difficult to me.