5 Replies Latest reply on May 31, 2007 9:42 AM by dimival

    Change States using Combo box

    Ayush.Jain
      I am creating a registration form with payment options in Adobe Flex . There would be 2 payment options, Cash and Credit card. when a user selects an option he/she has to fill in some details. I have created different states for credit and card option, which will appear as and when the option is selected. I am not able to get how to change to the respective state when an option is selected. Please help me in this regard.
        • 1. Re: Change States using Combo box
          dimival Level 1
          You would need to do something like:

          currentState = "nameOfYourState";

          That changes the state of your app. Now you want to do it whenever the comboBox changes, then you could do something like this:

          <mx:ComboBox id="payment" change="paymentState(event)"/>

          public function paymentState(event:Event):void
          {
          if(event.currentTarget.selectedItem == "Cash"){
          currentState = "CashState";
          else if (event.currentTarget.selectedItem == "Credit Card"){
          currentState = "CreditState";
          }
          }

          Hope this works for you
          • 2. Re: Change States using Combo box
            Ayush.Jain Level 1
            Hi..

            please review the code i have made. its not working. There are 3 states CashState, CreditState and ChequeState.

            <mx:Form width="380" height="100%" id="form1">
            <mx:FormItem label="Payment Method" >
            <mx:ComboBox id="payment" change="paymentState()">
            <mx:Object label="Select Payment Mode"/>
            <mx:Object id="crdit" label="Credit Card" data="Credit Card"/>
            <mx:Object id="chq" label="Cheque" data="Cheque"/>
            <mx:Object id="csh" label="Cash" data="Cash"/>
            </mx:ComboBox>

            </mx:FormItem>

            </mx:Form>
            <mx:Script>
            <![CDATA[

            public function paymentState():void
            {
            if(payment.selectedItem == "csh"){
            currentState = "CashState";
            }
            else if (payment.selectedItem == "crdit"){
            currentState = "CreditState";
            }
            else if (payment.selectedItem == "chq"){
            currentState = "ChequeState";
            }
            }
            ]]>
            </mx:Script>

            The script is not working. can you help me with this.

            Thanks,
            Ayush
            • 3. Re: Change States using Combo box
              dimival Level 1
              Try this:

              public function paymentState():void
              {
              if(payment.selectedItem.label == "Cash"){
              currentState = 'CashState';
              }
              else if (payment.selectedItem.label == "Credit Card"){
              currentState = 'CreditState';
              }
              else if (payment.selectedItem.label == "Cheque"){
              currentState = 'ChequeState';
              }
              }
              • 4. Re: Change States using Combo box
                Ayush.Jain Level 1
                It worked!! Thank you so much.. dimival

                • 5. Re: Change States using Combo box
                  dimival Level 1
                  Glad to help :)

                  Don't forget to close this topic by marking the post as the answer for the topic