DataSet.findFirst()

Availability

Flash Player 7.

Edition

Flash MX Professional 2004.

Usage

dataSetInstance.findFirst(searchValues)

Parameters

searchValues An array that contains one or more field values to be found within the current sort.

Returns

Returns true if the items are found; otherwise, returns false.

Description

Method; searches the current view of the collection for the first item with the field values specified by searchValues. Which items are in the current view depends on any current filter and range settings.

The values specified by searchValues must be in the same order as the field list specified by the current sort (see the example below).

Conversion of the data specified is based on the underlying field's type. For example, if the search value specified is ["05-02-02"], the underlying date field is used to convert the value with the date's setAsString() method. If the value specified is [new Date().getTime()], the date's setAsNumber() method is used.

Example

The following example uses DataSet.find() to search for an item in the current collection whose name and id fields contain the values "Bobby" and 105, respectively. If found, DataSet.getItemId() is used to get the unique identifier for that item, and DataSet.locateById() is used to position the current iterator at that item.

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 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:

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

trace("Before find() > " + student_ds.currentItem.name); // Billy

var studentID:String;
student_ds.addSort("id", ["name","id"]);
if (student_ds.find(["Bobby", 105])) {
    studentID = student_ds.getItemId();
    student_ds.locateById(studentID);
    trace("After find() > " + student_ds.currentItem.name); // Bobby
} else {
    trace("We lost Billy!");
}

See also

DataSet.applyUpdates(), DataSet.getItemId(), DataSet.locateById()


Flash CS3