DataSet.getIterator()

Availability

Flash Player 7.

Edition

Flash MX Professional 2004.

Usage

dataSetInstance.getIterator()

Returns

A ValueListIterator object.

Description

Method; returns a new iterator for this collection; this iterator is a clone of the current iterator in use, including its current position in the collection. This method is mainly for advanced users who want access to multiple, simultaneous views of the same collection.

Example

The following example uses DataSet.find() to search for an item in the current collection whose name field contain the value "Bobby". Even though the myIterator iterator is pointing to Bobby's record, the main iterator of student_ds still points to the last record, Billy.

To test this example, drag a DataSet component to the Stage, and give it an instance name of student_ds. Add two properties, name (data type: String) and id (data type: Number) to the DataSet component by using the Schema tab of the Component inspector. If you don't already have a copy of the DataBindingClasses compiled clip in your library, drag a copy of the compiled clip from the Classes library (Window > Common Libraries > Classes). Add the following ActionScript to Frame 1 of the main timeline:

import mx.data.to.ValueListIterator;

student_ds.addItem({name:"Barry", id:103});
student_ds.addItem({name:"Bobby", id:105});
student_ds.addItem({name:"Billy", id:107});

var myIterator:ValueListIterator = student_ds.getIterator();
myIterator.sortOn(["name"]);
myIterator.find({name:"Bobby"}).id = "999";

trace(student_ds.currentItem.name + " [" + student_ds.currentItem.id + "]");
    // Billy [107]

student_ds.addSort("id", ["name", "id"]);
if (student_ds.find({name:"Bobby", id:999})) {
    student_ds.locateById(student_ds.getItemId());
    trace(student_ds.currentItem.name + " [" + student_ds.currentItem.id + "]");
        // Bobby [999]
} else {
    trace("We lost Billy!");
}

Flash CS3