Flash CS3 Documentation |
|||
| ActionScript 2.0 Components Language Reference > DataSet component > DataSet.removeItemAt() | |||
Flash Player 7.
Flash MX Professional 2004.
dataSetInstance.removeItemAt(index)
index A number greater than or equal to 0. This number is the index of the item to remove.
A Boolean value indicating whether the item was removed.
Method; removes the item at the specified index. The indices after the removed index collapse by one.
This method triggers the modelChanged event with the event name removeItems.
In addition, it triggers the DataSet.removeItem event, which contains the result and item properties. The result property is used to determine if the item (referenced by the item property of the event) can be removed. By default, the result property is set to true. If no event listener is specified for the removeItem event, the item is removed by default.
An event listener can stop the item from being removed by listening for the removeItem event and setting the result property of the event to false, as shown in the following example:
function removeItem(evt_obj:Object):Void {
// Don't allow anyone to remove the item with customerId == 0.
evt_obj.result = (evt_obj.item.customerId != 0);
}
The following example removes an item from the data set at the first position:
my_ds.addItem({name:"Milton", years:3});
my_ds.addItem({name:"Mark", years:3});
my_ds.addItem({name:"Sarah", years:1});
my_ds.addItem({name:"Michael", years:2});
my_ds.addItem({name:"Frank", years:2});
trace(my_ds.getLength()); // 5
trace(my_ds.currentItem.name); // Frank
my_ds.removeItemAt(0);
trace(my_ds.getLength()); // 4
trace(my_ds.currentItem.name); // Frank
Flash CS3