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