EasyManua.ls Logo

MACROMEDIA FLASH 8-USING FLASH - Page 425

MACROMEDIA FLASH 8-USING FLASH
678 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
Data management (Flash Professional only) 425
The following code shows an example of accessing data at runtime. It loads an existing
DataSet component instance
myDataSet with customer information and then displays each
customer’s name in the trace window. Notice that the data types for the customer
information—the array of objects—are added so the data displays properly:
//Drag DataSet component to Stage and name it myDataSet (easiest way to
create instance and import necessary libraries)
//Creates recData which contains customer information in an array of objects
var recData = [{id:0, firstName:"Frank", lastName:"Jones", age:27,
usCitizen:true},
{id:1, firstName:"Susan", lastName:"Meth", age:55,
usCitizen:true},
{id:2, firstName:"Pablo", lastName:"Picasso", age:108,
usCitizen:false}];
//Assigns recData to the items property of the “myDataSet” DataSet component
instance
myDataSet.items = recData;
//Adds schema types for the expected fields
var i:mx.data.types.Str;
var j:mx.data.types.Num;
//Makes the first item the current item
myDataSet.first();
//Traces through the properties
while ( myDataSet.hasNext() ) {
//access the data through the Dataset properties
trace(myDataSet.firstName + " " + myDataSet.lastName);
myDataSet.next();
}
Design time example
Creating fields for a DataSet component at design time is another
way to expose the properties of a data object. After the fields are defined, you visually bind UI
controls to the data at design time. You can set additional properties (schema item settings) at
design time for a DataSet field to affect the way data is encoded, formatted, and validated at
runtime. For more information, see “Schema item settings on page 431.
To set up binding to this data at design time, you create persistent fields for the DataSet
component that represent the properties of the object. The following procedure shows an
example of how you would access the same customer information data at design time. You
bind the
recData array of objects to the items property of the DataSet component in
ActionScript, as in the runtime example. Then, you bind
DataGrid.dataProvider into
myDataSet.items using the Component inspector.

Table of Contents

Related product manuals