3 Replies Latest reply on Nov 13, 2009 8:23 AM by Pavlov.bsv@gmail.com

    ComboBox as "input" and add/remove items' problem

    Pavlov.bsv@gmail.com


      3-rd day goes to waste. And soon I'll be mad.  I cannot  correctly  do it despite the Adobe's topics (e.g. http://help.adobe.com/en_US/AS2LCR/Flash_10.0/help.html?content=Part4_AS2_Components_LangR ef_1.html). But I need:

       

      1) the user can enter the word (first sign - the Letter);

       

      2) the entered item is added  to the List of CheckBox;

       

      3) that List can be correctly sorted;

       

      4) WHAT I CANNOT MAKE: to be able to correctly remove the selected item. All indices after removing must properly changed:

       

      so, if I removed the item with index '4', the next indices would be descended (5=>4 etc.). How can I achieve it?

       


      You may have a quiet laugh over my desperation, but please help!

       

      mx.accessibility.ComboBoxAccImpl.enableAccessibility();
      
      my_cb.move(10, 10);
      clear_button.move(120, 10);
      my_cb.editable="true";
      imy_cb=0;
      icb_val='----';
      // Create dataprovider.
      var myDP_array:Array = new Array();
      myDP_array.push({data:imy_cb, label:icb_val});
      //myDP_array.push({data:2, label:"Second Item"});
      
      my_cb.dataProvider = myDP_array;
      
      // Define event listener object.
      var clearListener:Object = new Object();
      clearListener.click = function(evt1_obj:Object){
          for(j=0; j<q1m; j++){
              var leo:String=j+"\n"+_root.my_cb.text;
              if(leo==_global.yak){
                  _root.imy_cb=j;
                  _root.my_cb.removeItemAt(_root.imy_cb);
                  _root.imy_cb--;
                  trace("fe");
              }
          }
        trace(imy_cb);
          trace(j);
          trace(leo);
          trace(yak);
        _root.my_cb.sortItems(upperCaseFunc);
      }
      
      /*var plusListener:Object = new Object();
      plusListener.click = function(evt_obj:Object){
       my_cb.addItemAt(1);
      }*/
      
      // Add Listener.
      clear_button.addEventListener("click", clearListener);
      
      // сортировка массива
      my_cb.sortItems(upperCaseFunc);
      function upperCaseFunc(a, b){
      return a.label.toUpperCase() > b.label.toUpperCase();
      }
      
      function add_button_clicked() {
          
          _global.piu=1;
          
          if((my_cb.text!= '')&&(icb_val<> undefined)&&((my_cb.text.charAt(0)== 'А')||(my_cb.text.charAt(0)== 'а')||(my_cb.text.charAt(0)== 'Б')||(my_cb.text.charAt(0)== 'б')||(my_cb.text.charAt(0)== 'В')||(my_cb.text.charAt(0)== 'в')||(my_cb.text.charAt(0)== 'Г')||(my_cb.text.charAt(0)== 'г')||(my_cb.text.charAt(0)== 'Д')||(my_cb.text.charAt(0)== 'д')||(my_cb.text.charAt(0)== 'Е')||(my_cb.text.charAt(0)== 'е')||(my_cb.text.charAt(0)== 'Ё')||(my_cb.text.charAt(0)== 'ё')||(my_cb.text.charAt(0)== 'Ж')||(my_cb.text.charAt(0)== 'ж')||(my_cb.text.charAt(0)== 'З')||(my_cb.text.charAt(0)== 'з')||(my_cb.text.charAt(0)== 'И')||(my_cb.text.charAt(0)== 'и')||(my_cb.text.charAt(0)== 'Й')||(my_cb.text.charAt(0)== 'й')||(my_cb.text.charAt(0)== 'К')||(my_cb.text.charAt(0)== 'к')||(my_cb.text.charAt(0)== 'Л')||(my_cb.text.charAt(0)== 'л')||(my_cb.text.charAt(0)== 'М')||(my_cb.text.charAt(0)== 'м')||(my_cb.text.charAt(0)== 'Н')||(my_cb.text.charAt(0)== 'н')||(my_cb.text.charAt(0)== 'О')||(my_cb.text.charAt(0)== 'о')||(my_cb.text.charAt(0)== 'П')||(my_cb.text.charAt(0)== 'п')||(my_cb.text.charAt(0)== 'Р')||(my_cb.text.charAt(0)== 'р')||(my_cb.text.charAt(0)== 'С')||(my_cb.text.charAt(0)== 'с')||(my_cb.text.charAt(0)== 'Т')||(my_cb.text.charAt(0)== 'т')||(my_cb.text.charAt(0)== 'У')||(my_cb.text.charAt(0)== 'у')||(my_cb.text.charAt(0)== 'Ф')||(my_cb.text.charAt(0)== 'ф')||(my_cb.text.charAt(0)== 'Х')||(my_cb.text.charAt(0)== 'х')||(my_cb.text.charAt(0)== 'Ц')||(my_cb.text.charAt(0)== 'ц')||(my_cb.text.charAt(0)== 'Ч')||(my_cb.text.charAt(0)== 'ч')||(my_cb.text.charAt(0)== 'Ш')||(my_cb.text.charAt(0)== 'ш')||(my_cb.text.charAt(0)== 'Щ')||(my_cb.text.charAt(0)== 'щ')||(my_cb.text.charAt(0)== 'Ы')||(my_cb.text.charAt(0)== 'ы')||(my_cb.text.charAt(0)== 'Э')||(my_cb.text.charAt(0)== 'э')||(my_cb.text.charAt(0)== 'Ю')||(my_cb.text.charAt(0)== 'ю')||(my_cb.text.charAt(0)== 'Я')||(my_cb.text.charAt(0)== 'я'))){
          imy_cb+=1;  
          my_cb.addItem({data:imy_cb, label:icb_val});
          // сортировка массива
          my_cb.sortItems(upperCaseFunc);
      }
      
      
          //trace(my_cb.text);
      }
      
      add_button.addEventListener("click", add_button_clicked);
      
      var cbListener:Object = new Object();
      cbListener.change = function(evt_obj:Object) {
       var item_obj:Object = my_cb.selectedItem;
       var ij:String;
       for (ij in item_obj) {
      trace(item_obj[ij]);
      _global.yak=item_obj[ij];
       }
      // trace("");
      };
      my_cb.addEventListener("change", cbListener);
      
      this.onEnterFrame=function(){
         
          
          
        icb_val= my_cb.text;
         my_cb.restrict="a-zA-Z\\'\\,\\.\\А-Яа-я\u0020\u0401\u0451";
       q1m= my_cb.length;
      // trace(my_cb.selectedItem);
      }
      
      
      
      
        • 1. Re: ComboBox as "input" and add/remove items' problem
          Ned Murphy Adobe Community Professional & MVP

          In case it helps, I cannot understand what you are trying to do and what your problems are from your description.  You may need to take your time and carefully explain each aspect of what your are trying to ask for, including what works and what doesn't.  In any code you show, you should include comments and highlight the sections that are giving you problems.  I don't know if it applies or not, but you start talking about Check Boxes, when the title involves ComboBoxes, so you may need to sort things like that out properly.

          1 person found this helpful
          • 2. Re: ComboBox as "input" and add/remove items' problem
            Pavlov.bsv@gmail.com Level 1

            Sorry, Ned. My first post was my stupid error.)

             

            I can add to and select from my ComboBox items, but I cannot remove them.

             

            I have 3 components on the Scene: (below are their names in window Properties)

             

            1) my_cb -it is an Instance of ComboBox;

            2) clear_button -an Instance of Button;

            3) add_button -another Instance of Button;

             

            that is the 1st piece of code:

            my_cb.move(10, 10);
            clear_button.move(120, 10);
            add_button.move(10, 45);
            my_cb.editable="true";
            
            imy_cb=0; // var for ComboBox' index by load
            icb_val='----'; // var for item's value by load
            
            var myDP_array:Array = new Array(); // Create dataprovider for ComboBox
            myDP_array.push({data:imy_cb, label:icb_val}); // 1st item for the list
            
            my_cb.dataProvider = myDP_array; // define dataProvider for ComboBox
            

             

            Then is my 'ugly' remove-event: I want it to work correctly:

            var clearListener:Object = new Object();          // Define remove-event listener object.
            clearListener.click = function(evt1_obj:Object){
                for(j=0; j<q1m; j++){    
                    var leo:String=j+"\n"+_root.my_cb.text; // my prompt to compare icb_val with item_obj[ij] from my_cb.selectedItem, see below
                    if(leo==_global.yak){ // as above
                        _root.imy_cb=j;
                        _root.my_cb.removeItemAt(_root.imy_cb);
                        _root.imy_cb--;
                        trace("fe"); // the mark of success (no output)
                    }
                }
              trace(imy_cb); // different vars, as above
                trace(j);
                trace(leo);
              
              _root.my_cb.sortItems(upperCaseFunc); // sorting

            }

             

            Add the clearListener to the button:

             

            clear_button.addEventListener("click", clearListener);
            
            

             

            Also add the sort-function:

             

            my_cb.sortItems(upperCaseFunc);
            function upperCaseFunc(a, b){
            return a.label.toUpperCase() > b.label.toUpperCase();
            }
            

             

            Add-function - it's ugly, but it works (thus I try to forbid to enter non-literal sign as the 1st sign; restrict doesn't help):

             

            function add_button_clicked() {
                
                _global.piu=1;
                
                if((my_cb.text!= '')&&(icb_val<> undefined)&&((my_cb.text.charAt(0)== 'А')||(my_cb.text.charAt(0)== 'а')||(my_cb.text.charAt(0)== 'Б')||(my_cb.text.charAt(0)== 'б')||(my_cb.text.charAt(0)== 'В')||(my_cb.text.charAt(0)== 'в')||(my_cb.text.charAt(0)== 'Г')||(my_cb.text.charAt(0)== 'г')||(my_cb.text.charAt(0)== 'Д')||(my_cb.text.charAt(0)== 'д')||(my_cb.text.charAt(0)== 'Е')||(my_cb.text.charAt(0)== 'е')||(my_cb.text.charAt(0)== 'Ё')||(my_cb.text.charAt(0)== 'ё')||(my_cb.text.charAt(0)== 'Ж')||(my_cb.text.charAt(0)== 'ж')||(my_cb.text.charAt(0)== 'З')||(my_cb.text.charAt(0)== 'з')||(my_cb.text.charAt(0)== 'И')||(my_cb.text.charAt(0)== 'и')||(my_cb.text.charAt(0)== 'Й')||(my_cb.text.charAt(0)== 'й')||(my_cb.text.charAt(0)== 'К')||(my_cb.text.charAt(0)== 'к')||(my_cb.text.charAt(0)== 'Л')||(my_cb.text.charAt(0)== 'л')||(my_cb.text.charAt(0)== 'М')||(my_cb.text.charAt(0)== 'м')||(my_cb.text.charAt(0)== 'Н')||(my_cb.text.charAt(0)== 'н')||(my_cb.text.charAt(0)== 'О')||(my_cb.text.charAt(0)== 'о')||(my_cb.text.charAt(0)== 'П')||(my_cb.text.charAt(0)== 'п')||(my_cb.text.charAt(0)== 'Р')||(my_cb.text.charAt(0)== 'р')||(my_cb.text.charAt(0)== 'С')||(my_cb.text.charAt(0)== 'с')||(my_cb.text.charAt(0)== 'Т')||(my_cb.text.charAt(0)== 'т')||(my_cb.text.charAt(0)== 'У')||(my_cb.text.charAt(0)== 'у')||(my_cb.text.charAt(0)== 'Ф')||(my_cb.text.charAt(0)== 'ф')||(my_cb.text.charAt(0)== 'Х')||(my_cb.text.charAt(0)== 'х')||(my_cb.text.charAt(0)== 'Ц')||(my_cb.text.charAt(0)== 'ц')||(my_cb.text.charAt(0)== 'Ч')||(my_cb.text.charAt(0)== 'ч')||(my_cb.text.charAt(0)== 'Ш')||(my_cb.text.charAt(0)== 'ш')||(my_cb.text.charAt(0)== 'Щ')||(my_cb.text.charAt(0)== 'щ')||(my_cb.text.charAt(0)== 'Ы')||(my_cb.text.charAt(0)== 'ы')||(my_cb.text.charAt(0)== 'Э')||(my_cb.text.charAt(0)== 'э')||(my_cb.text.charAt(0)== 'Ю')||(my_cb.text.charAt(0)== 'ю')||(my_cb.text.charAt(0)== 'Я')||(my_cb.text.charAt(0)== 'я'))){
                imy_cb+=1;  
                my_cb.addItem({data:imy_cb, label:icb_val});
                // сортировка массива
                my_cb.sortItems(upperCaseFunc);
            }
            
            
                //trace(my_cb.text);
            }
            add_button.addEventListener("click", add_button_clicked);
            
            

             

            So I "used" the .selectedItem:

            var cbListener:Object = new Object();
            cbListener.change = function(evt_obj:Object) {
             var item_obj:Object = my_cb.selectedItem;
             var ij:String;
             for (ij in item_obj) {
            trace(item_obj[ij]);
            _global.yak=item_obj[ij];
             }
            // trace("");
            };
            my_cb.addEventListener("change", cbListener);
            

            And onEnterFrame with restrict: I have some doubts about that function and, particularly, about  icb_val= my_cb.text;

             

            this.onEnterFrame=function(){
                
              icb_val= my_cb.text;
               my_cb.restrict="a-zA-Z\\'\\,\\.\\А-Яа-я\u0020\u0401\u0451";
             q1m= my_cb.length;
            // trace(my_cb.selectedItem);
            }

             

             

            But the main question is: how to remove the selected item?

            • 3. Re: ComboBox as "input" and add/remove items' problem
              Pavlov.bsv@gmail.com Level 1

              Sorry, Ned. My first post was my stupid error.)

               

              I can add to and select from my ComboBox items, but I cannot remove them.

               

              I have 3 components on the Scene: (below are their names in window Properties)

               

              1) my_cb -it is an Instance of ComboBox;

              2) clear_button -an Instance of Button;

              3) add_button -another Instance of Button;

               

              that is the 1st piece of code:

              my_cb.move(10, 10);
              clear_button.move(120, 10);
              add_button.move(10, 45);
              my_cb.editable="true";
              
              imy_cb=0; // var for ComboBox' index by load
              icb_val='----'; // var for item's value by load
              
              var myDP_array:Array = new Array(); // Create dataprovider for ComboBox
              myDP_array.push({data:imy_cb, label:icb_val}); // 1st item for the list
              
              my_cb.dataProvider = myDP_array; // define dataProvider for ComboBox
              

               

              Then is my 'ugly' remove-event: I want it to work correctly:

              var clearListener:Object = new Object();          // Define remove-event listener object.
              clearListener.click = function(evt1_obj:Object){
                  for(j=0; j<q1m; j++){    
                      var leo:String=j+"\n"+_root.my_cb.text; // my prompt to compare icb_val with item_obj[ij] from my_cb.selectedItem, see below
                      if(leo==_global.yak){ // as above
                          _root.imy_cb=j;
                          _root.my_cb.removeItemAt(_root.imy_cb);
                          _root.imy_cb--;
                          trace("fe"); // the mark of success (no output)
                      }
                  }
                trace(imy_cb); // different vars, as above
                  trace(j);
                  trace(leo);
                
                _root.my_cb.sortItems(upperCaseFunc); // sorting

              }

               

              Add the clearListener to the button:

               

              clear_button.addEventListener("click", clearListener);
              
              

               

              Also add the sort-function:

               

              my_cb.sortItems(upperCaseFunc);
              function upperCaseFunc(a, b){
              return a.label.toUpperCase() > b.label.toUpperCase();
              }
              

               

              Add-function - it's ugly, but it works (thus I try to forbid to enter non-literal sign as the 1st sign; restrict doesn't help):

               

              function add_button_clicked() {
                  
                  _global.piu=1;
                  
                  if((my_cb.text!= '')&&(icb_val<> undefined)&&((my_cb.text.charAt(0)== 'А')||(my_cb.text.charAt(0)== 'а')||(my_cb.text.charAt(0)== 'Б')||(my_cb.text.charAt(0)== 'б')||(my_cb.text.charAt(0)== 'В')||(my_cb.text.charAt(0)== 'в')||(my_cb.text.charAt(0)== 'Г')||(my_cb.text.charAt(0)== 'г')||(my_cb.text.charAt(0)== 'Д')||(my_cb.text.charAt(0)== 'д')||(my_cb.text.charAt(0)== 'Е')||(my_cb.text.charAt(0)== 'е')||(my_cb.text.charAt(0)== 'Ё')||(my_cb.text.charAt(0)== 'ё')||(my_cb.text.charAt(0)== 'Ж')||(my_cb.text.charAt(0)== 'ж')||(my_cb.text.charAt(0)== 'З')||(my_cb.text.charAt(0)== 'з')||(my_cb.text.charAt(0)== 'И')||(my_cb.text.charAt(0)== 'и')||(my_cb.text.charAt(0)== 'Й')||(my_cb.text.charAt(0)== 'й')||(my_cb.text.charAt(0)== 'К')||(my_cb.text.charAt(0)== 'к')||(my_cb.text.charAt(0)== 'Л')||(my_cb.text.charAt(0)== 'л')||(my_cb.text.charAt(0)== 'М')||(my_cb.text.charAt(0)== 'м')||(my_cb.text.charAt(0)== 'Н')||(my_cb.text.charAt(0)== 'н')||(my_cb.text.charAt(0)== 'О')||(my_cb.text.charAt(0)== 'о')||(my_cb.text.charAt(0)== 'П')||(my_cb.text.charAt(0)== 'п')||(my_cb.text.charAt(0)== 'Р')||(my_cb.text.charAt(0)== 'р')||(my_cb.text.charAt(0)== 'С')||(my_cb.text.charAt(0)== 'с')||(my_cb.text.charAt(0)== 'Т')||(my_cb.text.charAt(0)== 'т')||(my_cb.text.charAt(0)== 'У')||(my_cb.text.charAt(0)== 'у')||(my_cb.text.charAt(0)== 'Ф')||(my_cb.text.charAt(0)== 'ф')||(my_cb.text.charAt(0)== 'Х')||(my_cb.text.charAt(0)== 'х')||(my_cb.text.charAt(0)== 'Ц')||(my_cb.text.charAt(0)== 'ц')||(my_cb.text.charAt(0)== 'Ч')||(my_cb.text.charAt(0)== 'ч')||(my_cb.text.charAt(0)== 'Ш')||(my_cb.text.charAt(0)== 'ш')||(my_cb.text.charAt(0)== 'Щ')||(my_cb.text.charAt(0)== 'щ')||(my_cb.text.charAt(0)== 'Ы')||(my_cb.text.charAt(0)== 'ы')||(my_cb.text.charAt(0)== 'Э')||(my_cb.text.charAt(0)== 'э')||(my_cb.text.charAt(0)== 'Ю')||(my_cb.text.charAt(0)== 'ю')||(my_cb.text.charAt(0)== 'Я')||(my_cb.text.charAt(0)== 'я'))){
                  imy_cb+=1;  
                  my_cb.addItem({data:imy_cb, label:icb_val});
                  // сортировка массива
                  my_cb.sortItems(upperCaseFunc);
              }
              
              
                  //trace(my_cb.text);
              }
              add_button.addEventListener("click", add_button_clicked);
              
              

               

              So I "used" the .selectedItem:

              var cbListener:Object = new Object();
              cbListener.change = function(evt_obj:Object) {
               var item_obj:Object = my_cb.selectedItem;
               var ij:String;
               for (ij in item_obj) {
              trace(item_obj[ij]);
              _global.yak=item_obj[ij];
               }
              // trace("");
              };
              my_cb.addEventListener("change", cbListener);
              

              And onEnterFrame with restrict: I have some doubts about that function and, particularly, about  icb_val= my_cb.text;

               

              this.onEnterFrame=function(){
                  
                icb_val= my_cb.text;
                 my_cb.restrict="a-zA-Z\\'\\,\\.\\А-Яа-я\u0020\u0401\u0451";
               q1m= my_cb.length;
              // trace(my_cb.selectedItem);
              }



              But the main question is: how to remove the selected item?