Heres a quick answer from my undercafineated brain
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml";>
<mx:List id="myStateList"  dataProvider="{statesList}" 
multipleSelection="true" />
<mx:Button label="Remove States" click="dStates(event)"/>
<mx:Script>
<![CDATA[
         var statesList:Array=new Array("AZ","CA","NV","MD","NY");
         function dStates(event:Object):Void {
                 var lb = myStateList;
                 for ( var i = lb.length; i >=0 ; i--){
                         if(isInArray(lb.getItemAt(i),lb.selectedItems)){
                                  myStateList.removeItemAt(i);
                         }
                 }
         }
         function isInArray(item:String,array:Array):Boolean{
                 for(var i=0;i<array.length;i++){
                         if(array[i] == item){
                                 return true;
                         }
                 }
                 return false;
         }
]]>
</mx:Script>
</mx:Application>

Essentially loop over all items in the list box, compare each to the 
selectedItems.  If a match, delete.  The may well be a more elegant 
solution, but I'd need coffee for that


At 06:47 AM 5/1/2005, you wrote:
>I am sure there is an easy answer for this but I have tried a few
>things and not sure where to go from here. I have a list that is
>populated from an array in a function.
>
><mx:List id="myStateList" dataProvider="{statesList.states}"
>multipleSelection="true" />
>
>
>The array in the list is states:
>
>AZ
>CA
>NV
>MD
>NY
>
>I would like to delete multiple items with one click of a button. So
>if I select CA and MD, I would like to delete them from the list.
>
>My button has this call.
>
><mx:Button label="Remove States" click="statesList.dStates
>(myStateList.selectedIndices)"/>
>
>That returns an array of (1,3)
>
>My Actionscript page (statesList) has this function.
>
>function dStates(delState:Array):Void {
>
>               for ( var i = 0; i < delState.length; i++){
>                      states.removeItemAt(delState[i]);
>                     }
>}
>
>But what happens is that this will delete CA and NY. I understand why
>this is happening (because states is getting reset and the second
>time through the loop, NY is in the 3rd position of the array) so how
>else can I do this.
>
>Thank you for any help.
>
>
>
>
>
>----------
>Yahoo! Groups Links
>    * To visit your group on the web, go to:
>    * 
> <http://groups.yahoo.com/group/flexcoders/>http://groups.yahoo.com/group/flexcoders/
>  
>
>    *
>    * To unsubscribe from this group, send an email to:
>    * 
> <mailto:[EMAIL PROTECTED]>[EMAIL PROTECTED] 
>
>    *
>    * Your use of Yahoo! Groups is subject to the 
> <http://docs.yahoo.com/info/terms/>Yahoo! Terms of Service.



 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/flexcoders/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



Reply via email to