DataSet.addItem

Availability

Flash Player 7.

Edition

Flash MX Professional 2004.

Usage

Usage 1:

var listenerObject:Object = new Object();
listenerObject.addItem = function (eventObj:Object) {
    // ...
};
dataSetInstance.addEventListener("addItem", listenerObject);

Usage 2:

on (addItem) {
    // ...
}

Description

Event; generated just before a new record (transfer object) is inserted into this collection.

If you set the result property of the event object to false, the add operation is canceled; if you set it to true, the add operation is allowed.

The event object (eventObj) contains the following properties:

target The DataSet object that generated the event.

type The string "addItem".

item A reference to the item in the collection to be added.

result A Boolean value that specifies whether the specified item should be added. By default, this value is true.

Example

The following addItem event handler cancels the addition of the new item if a user-defined function named userHasAdminPrivs() returns false; otherwise, the item addition is allowed.

function userHasAdminPrivs():Boolean {
    return false; // Change this to true to allow inserts. 
}

my_ds.addEventListener("addItem", addItemListener);
my_ds.addItem({name:"Bobo", occupation:"clown"});

function addItemListener(evt_obj:Object):Void {
    if (userHasAdminPrivs()) {
        // Allow the item addition.
        evt_obj.result = true;
        trace("Item added");
    } else {
        // Don't allow item addition; user doesn't have admin privileges.
        evt_obj.result = false;
        trace("Error, insufficient permissions");
    }
}

See also

DataSet.removeItem


Flash CS3