5 Replies Latest reply on May 28, 2007 10:25 PM by Rahul Mainkar

    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
          jeannat
          Did you try setting the currentState on the change event when the option is selected by a click on a radiobutton?

          change="currentState='some_needed_option_state' "
          • 2. Re: Change States using Combo box
            Rahul Mainkar Level 1
            Hi Ayush,
            One more suggestion, try to use a function to toggle in between the states.
            Ex. cb is the ID of your comboBox.

            change= {someFunction()}

            private function someFunction():void{
            if(cb.text=="cash")
            currentState='cashState';
            else
            currentState='chequeState''
            }

            Here cashState and Cheque states are the names of corresponding states that you want to toggle.

            • 3. 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
              • 4. Re: Change States using Combo box
                Rahul Mainkar Level 1
                Here is a sample code for your querry.

                <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" >
                <mx:states>
                <mx:State name="Cash">
                <mx:AddChild position="lastChild">
                <mx:Label x="372" y="112" text="Cash State"/>
                </mx:AddChild>
                </mx:State>
                </mx:states>

                <mx:Script>
                <![CDATA[

                private function changeState():void{
                if(cBox.text=="Cash")
                {
                currentState='Cash'
                }
                }

                <mx:ComboBox id="cBox" x="352" y="42" change="changeState()">
                <mx:dataProvider>
                <mx:Array>
                <mx:String>SelectPaymentMode</mx:String>
                <mx:String>Cash</mx:String>
                <mx:String>Cheque</mx:String>
                </mx:Array>
                </mx:dataProvider>
                </mx:ComboBox>
                </mx:Application>



                Here Cash is a new state. when you select Cash from the combobox, current state is changed to cash state.
                I hope this will solve your querry.
                • 5. Re: Change States using Combo box
                  Rahul Mainkar Level 1
                  Here is a sample code for your querry.

                  <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute" >
                  <mx:states>
                  <mx:State name="Cash">
                  <mx:AddChild position="lastChild">
                  <mx:Label x="372" y="112" text="Cash State"/>
                  </mx:AddChild>
                  </mx:State>
                  </mx:states>

                  <mx:Script>
                  <![CDATA[

                  private function changeState():void{
                  if(cBox.text=="Cash")
                  {
                  currentState='Cash'
                  }
                  }

                  <mx:ComboBox id="cBox" x="352" y="42" change="changeState()">
                  <mx:dataProvider>
                  <mx:Array>
                  <mx:String>SelectPaymentMode</mx:String>
                  <mx:String>Cash</mx:String>
                  <mx:String>Cheque</mx:String>
                  </mx:Array>
                  </mx:dataProvider>
                  </mx:ComboBox>
                  </mx:Application>



                  Here Cash is a new state. when you select Cash from the combobox, current state is changed to cash state.
                  I hope this will solve your querry.