List.removeItemAt()

Availability

Flash Player 6 (6.0.79.0).

Edition

Flash MX 2004.

Usage

listInstance.removeItemAt(index)

Parameters

index A number that indicates the position of the item. The value must be greater than 0 and less than List.length.

Returns

An object; the removed item (undefined if no item exists).

Description

Method; removes the item at the specified index position. The list indices after the specified index collapse by one.

Calling this method modifies the data provider of the List component. If the data provider is shared with other components, those components are updated as well.

Example

The following code clears the selected item in a List component when a button is clicked. To try this code, drag a List component to the Stage and give it the instance name my_list. Next, drag a Button component to the Stage and give it the instance name remove_button. Add the following code to Frame 1 in the timeline:

var my_list:mx.controls.List;
var remove_button:mx.controls.Button;

remove_button.label = "Remove";

my_list.addItem({data:"flash", label:"Flash"});
my_list.addItem({data:"dreamweaver", label:"Dreamweaver"});
my_list.addItem({data:"coldfusion", label:"ColdFusion"});

var buttonListener:Object = new Object();
buttonListener.click = function(evt_obj:Object) {
    if (my_list.selectedIndex != undefined) {
        my_list.removeItemAt(my_list.selectedIndex);
    }
}
remove_button.addEventListener("click", buttonListener);