Example
In the following example, events are disabled before changes are made to items in the
collection, so that the DataSet object won't affect performance by trying to refresh controls.
my_ds.addEventListener("modelChanged", onModelChanged);
function onModelChanged(evt_obj:Object):Void {
trace("model changed, DataSet now has " + evt_obj.target.items.length + "
items");
}
// Disable events for the data set.
my_ds.disableEvents();
my_ds.addItem({name:"Apples", price:14});
my_ds.addItem({name:"Bananas", price:8});
trace("Before:");
traceItems();
my_ds.last();
while(my_ds.hasPrevious()) {
my_ds.price *= 0.5; // Everything's 50% off!
my_ds.previous();
}
trace("After:");
traceItems();
// Tell the data set it's time to update the controls now.
my_ds.enableEvents();
function traceItems():Void {
for (var i:Number = 0; i < my_ds.items.length; i++) {
trace("\t" + my_ds.items[i].name + " - $" + my_ds.items[i].price);
}
trace("");
}
See also
DataSet.disableEvents()
358
Components Dictionary
Need help?
Do you have a question about the FLASH 8-COMPONENTS LANGUAGE and is the answer not in the manual?