MACROMEDIA FLASH MX 2004-USING COMPONENTS Use Manual page 36

Using components
Hide thumbs Also See for FLASH MX 2004-USING COMPONENTS:
Table of Contents

Advertisement

Add columns to the Gift Ideas section
Now you're ready to add columns to the data grid in the Gift Ideas section of the application, for
displaying product information and price.
In the Actions panel, add the following code to create, configure, and add a Name column and
a Price column to the DataGrid instance:
// define data grid columns and their default widths in the products_dg
// DataGrid instance
var name_dgc:DataGridColumn = new DataGridColumn("name");
name_dgc.headerText = "Name";
name_dgc.width = 280;
// add the column to the DataGrid
products_dg.addColumn(name_dgc);
var price_dgc:DataGridColumn = new DataGridColumn("price");
price_dgc.headerText = "Price";
price_dgc.width = 100;
// define the function that will be used to set the column's label
// at runtime
price_dgc.labelFunction = function(item:Object) {
if (item != undefined) {
return "$"+item.price+" "+item.priceQualifier;
}
};
products_dg.addColumn(price_dgc);
Connect to a web service to populate the combo box
In this section you'll add code to connect to a web service that contains the list of blunders
(Forgot to Water Your Plants, and so on). The web service description language (WSDL) file is
located at www.flash-mx.com/mm/firstapp/problems.cfc?WSDL. To see how the WSDL is
structured, point your browser to the WSDL location.
The ActionScript code passes the web service results to the ComboBox instance for display. A
function sorts the blunders in order of severity. If no result is returned from the web service (for
example, if the service is down, or the function isn't found), an error message appears in the
Output panel.
In the Actions panel, add the following code:
/* Define the web service used to retrieve an array of problems.
This service will be bound to the problems_cb ComboBox instance. */
var problemService:WebService = new WebService("http://www.flash-mx.com/mm/
firstapp/problems.cfc?WSDL");
var myProblems:Object = problemService.getProblems();
/* If you get a result from the web service, set the field that will be used
for the column label.
Set the data provider to the results returned from the web service. */
myProblems.onResult = function(wsdlResults:Array) {
problems_cb.labelField = "name";
problems_cb.dataProvider = wsdlResults.sortOn("severity", Array.NUMERIC);
36
Chapter 2: Creating an Application with Components (Flash Professional Only)

Advertisement

Table of Contents
loading
Need help?

Need help?

Do you have a question about the FLASH MX 2004-USING COMPONENTS and is the answer not in the manual?

Questions and answers

This manual is also suitable for:

Flash mx

Table of Contents