2 Replies Latest reply on Sep 27, 2009 7:35 AM by jYeory

    I have some problem in loop

    jYeory

      Hi, I'm studying FLEX in Korea.

      (I'm not that good at English)

       

      I have a issue and I couldn't solve it.

       

      problem01.jpg

       

      If click the OK button, will execute doVailidate method.

       

      .....
      
      public function doValidate():void{
          var params:Object = null;
          var ti:TextInput = null;
          var combo:ComboBox = null;
          
          var children:Array = joinForm.getChildren();
          if (params == null) params = new Object();
      
          for(var i:int=0; i<children.length; i++){
           //Total : 20
           Alert.show("Count in loop : "+i+" , Totol Count : "+children.length.toString());
           //How I can see over seventh item?
      
           var strArray:Array = children[i].toString().split(".");
           var id:String = strArray[strArray.length-1].toString();
           
           var prefix:Boolean = id.substr(0, 2) == "p_";
           var comboCondition:Boolean = prefix && id.substr(id.length-5, id.length) == "Combo";
           var textCondition:Boolean = prefix && id.substr(id.length-5, id.length) != "Combo";
           
           if(comboCondition){
                combo = ComboBox(children[i]);
                params[id] = combo.selectedItem.data;
           } else if(textCondition){
                ti = TextInput(children[i]);     // x1
                params[id] = ti.text;            // x2
           }
          }
         }
      ...
      

      problem02.jpg

      (I can't see over seventh number)

       

       

      I can see all items by Alert.show() after delete line x1 and x2.

       

      download the attach files and run it.

       

      If you solved this issue, please send email me. (leepcs@naver.com)

       

      Please SAVE ME !

      I failed to resolve this issue for all day.

        • 1. Re: I have some problem in loop
          paul.williams Level 4

          In the 7th iteration of your loop the id value is "p_birthday" and this maps to a DateField, but you are trying to cast it to a TextInput. If you run the application in debug mode you will see that this causes an Error to be thrown, which exits the loop:

           

          TypeError: Error #1034: Type Coercion failed: cannot convert mx.controls::DateField@f13e0a1 to mx.controls.TextInput.
              at ValidationLoop/doValidate()[C:\workspaces\general\ValidationLoop\src\ValidationLoop.mxml: 59]
              at ValidationLoop/___ValidationLoop_Button1_click()[C:\workspaces\general\ValidationLoop\src \ValidationLoop.mxml:117]

           

          A better way to check the type of an object is with the 'is' operator:

           

               var isTextInput : Boolean = children[ i ] is TextInput;

          • 2. Re: I have some problem in loop
            jYeory Level 1

            Thanks p_m_williams!!

             

            Why I coun't think debug mode

             

             

            your reply is very helpful to me

             

            very thank you!!

             

            (-.-)(_._)(-.-)(_._)