User Guide

DataSet component (Flash Professional only) 303
To create an application using the DataSet component:
1.
In Flash MX Professional 2004, select File > New. In the Type column, select Flash Document
and click OK.
2.
Open the Components panel if it’s not already open.
3.
Drag a DataSet component from the Components panel to the Stage. In the Property inspector,
give it the instance name userData.
4.
Drag a DataGrid component to the Stage and give it the instance name userGrid.
5.
Resize the DataGrid component to be approximately 300 pixels wide and 100 pixels tall.
6.
Drag a Button component to the Stage and set its instance name to nextBtn.
7.
In the Timeline, select the first frame on Layer 1 and open the Actions panel.
8.
Add the following code to the Actions panel:
var recData = [{id:0, firstName:"Mick", lastName:"Jones"},
{id:1, firstName:"Joe", lastName:"Strummer"},
{id:2, firstName:"Paul", lastName:"Simonon"}];
userData.items = recData;
This populates the DataSet objects items property with an array of objects, each of which has
three properties:
id, firstName, and lastName.
9.
Add the three properties and their required data types to the DataSet schema:
a
Select the DataSet component on the Stage, open the Component inspector, and click the
Schema tab.
b
Click Add Component Property, and add three new properties, with field names 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;
10.
To bind the contents of the DataSet component to the contents of the DataGrid component,
open the Component inspector and click the Bindings tab.
11.
Select the DataGrid component (userGrid) on the Stage, and click the Add Binding (+) button
in the Component inspector.
12.
In the Add Binding dialog box, select “dataProvider : Array” and click OK.
13.
Double-click the Bound To field in the Component inspector.
14.
In the Bound To dialog box that appears, select “DataSet <userData>” from the Component
Path column and then select “dataProvider : Array” from the Schema Location column.
15.
To bind the selected index of the DataSet component to the selected index of the DataGrid
component, select the DataGrid component on the Stage and click the Add Binding (+) button
again in the Component inspector.
16.
In the dialog box that appears, select “selectedIndex : Number”. Click OK.