Flash CS3 Documentation |
|||
| ActionScript 2.0 Components Language Reference > DataSet component > Using the DataSet component > Creating an application with the DataSet component | |||
Typically, you use the DataSet component with other user interface components, and often with a connector component such as XMLConnector or WebServiceConnector. The items in the data set are populated by means of the connector component or raw ActionScript data, and then bound to user interface controls (such as List or DataGrid components).
The DataSet component uses functionality in the data binding classes. If you intend to work with the DataSet component in ActionScript only, without using the Binding and Schema tabs in the Component inspector to set properties, you'll need to import the data binding classes into your FLA file and set required properties in your code. See Making data binding classes available at runtime.
var recData_array:Array = [{id:0, firstName:"Mick", lastName:"Jones"},
{id:1, firstName:"Joe", lastName:"Strummer"},
{id:2, firstName:"Paul", lastName:"Simonon"}];
user_ds.items = recData_array;
This populates the DataSet object's items property with an array of objects, each of which has three properties: id, firstName, and lastName.
id, firstName, and lastName, and data types Number, String, and String, respectively.Or, if you prefer to add the properties and their required data types in code, you can add the following line of code to the Actions panel instead of following steps a and b above:
// Add required schema types. var i:mx.data.types.Str; var j:mx.data.types.Num;
user_dg) on the Stage, and click the Add Binding (+) button in the Component inspector.
next_button.addEventListener("click", nextBtnClick);
function nextBtnClick(evt_obj:Object):Void {
user_ds.next();
}
This code uses the DataSet.next() method to navigate to the next item in the DataSet object's collection of items. Since you had previously bound the selectedIndex property of the DataGrid object to the same property of the DataSet object, changing the current item in the DataSet object changes the current (selected) item in the DataGrid object as well.
The DataGrid object is populated with the specified items. Notice how clicking the button changes the selected item in the DataGrid object.
Flash CS3