Flash CS3 Documentation |
|||
| ActionScript 2.0 Components Language Reference > DataSet component > DataSet.getItemId() | |||
Flash Player 7.
Flash MX Professional 2004.
dataSetInstance.getItemId([index])
index A number specifying the item in the current view for which to get the ID. This parameter is optional.
A string.
Method; returns the identifier of the current item in the collection, or that of the item specified by index. This identifier is unique only in this collection and is assigned automatically by DataSet.addItem().
The following code gets the unique ID for the current item in the collection and then displays it in the Output panel.
var itemNo:String = my_ds.getItemId();
trace("Employee id(" + itemNo + ")");
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!");
}
Flash CS3