Skip to main content
Inspiring
May 26, 2011
Answered

cannot detect if there is only 1 element in combo box?

  • May 26, 2011
  • 1 reply
  • 286 views

I have an array of strings to set them into the combo box, a drop down combo box. I will select an element in the drop down combo box and press the button "delete". It will delete the element from the combo box. but when I come to the last combo box, im unable to delete it off because it does not get pass this line....

myEntries.selectedItem.label == myArray

why does myEntries.selectedItem.label isnt being detected in the last element?

Entries.addEventListener(Event.CHANGE, EntriesChange)

               }

          }

          

          var str_entries:String="";

          //set default

          function EntriesChange(e:Event):void{

               for(var i=0;i<myArray.length;i++)

               {

                    if (myEntries.selectedItem.label == myArray){

                         str_entries = myArray;

                         trace("str_entries="+str_entries)

                    }

               }

          }

This topic has been closed for replies.
Correct answer relaxatraja

You can't able to remove the 0th index, the below code does the trick:

delbtn.addEventListener(MouseEvent.CLICK,delfn);
function delfn(e:MouseEvent):void{
    var str:String=String(Entries.selectedItem.label).toLowerCase();
    for(var i=0;i<myArray.length;i++){
        var str1:String=String(myArray).toLowerCase();
        if (str == str1){
        Entries.removeItem(Entries.selectedItem);
        if (Entries.length==0) Entries.removeAll();
        str_entries = myArray;
    }
    }
}

1 reply

relaxatraja
relaxatrajaCorrect answer
Inspiring
May 26, 2011

You can't able to remove the 0th index, the below code does the trick:

delbtn.addEventListener(MouseEvent.CLICK,delfn);
function delfn(e:MouseEvent):void{
    var str:String=String(Entries.selectedItem.label).toLowerCase();
    for(var i=0;i<myArray.length;i++){
        var str1:String=String(myArray).toLowerCase();
        if (str == str1){
        Entries.removeItem(Entries.selectedItem);
        if (Entries.length==0) Entries.removeAll();
        str_entries = myArray;
    }
    }
}