Flash CS3 Documentation |
|||
| ActionScript 2.0 Components Language Reference > DataSet component > DataSet.removeItem | |||
Flash Player 7.
Flash MX Professional 2004.
Usage 1:
var listenerObject:Object= new Object();listenerObject.removeItem = function (eventObj:Object):Void { // ... };dataSetInstance.addEventListener("removeItem",listenerObject);
Usage 2:
on (removeItem) {
// ...
}
Event; generated just before a new item is deleted from this collection.
If you set the result property of the event object to false, the delete operation is canceled; if you set it to true, the delete operation is allowed.
The event object (eventObj) contains the following properties:
target The DataSet object that generated the event.
type The string "removeItem".
item A reference to the item in the collection to be removed.
result A Boolean value that specifies whether the item should be removed. By default, this value is true.
In the following example, an on(removeItem) event handler cancels the deletion of the new item if a user-defined function named userHasAdminPrivs() returns false; otherwise, the deletion is allowed:
on (removeItem) {
if (globalObj.userHasAdminPrivs()) {
// Allow the item deletion.
eventObj.result = true;
} else {
// Don't allow the item deletion; user doesn't have admin privileges.
eventObj.result = false;
}
}
The following removeItem event handler cancels the removal of the existing item if a user-defined function named userHasAdminPrivs() returns false; otherwise, the item removal is allowed:
function userHasAdminPrivs():Boolean {
return false; // change this to true to allow inserts
}
function removeItemListener(evt_obj:Object):Void {
if (userHasAdminPrivs()) {
// Allow the item removal.
evt_obj.result = true;
trace("Item removed");
} else {
// Don't allow item removal; user doesn't have admin privileges.
evt_obj.result = false;
trace("Error, insufficient permissions");
}
}
my_ds.addEventListener("removeItem", removeItemListener);
my_ds.addItem({name:"item a", price:16});
my_ds.addItem({name:"item b", price:9});
my_ds.removeItemAt(0);
Flash CS3