2003 Macromedia, Inc. 16
Populating a Datagrid with Dynamic Data
In this section, instead of linking your Combo Box to a List Box, you will
link the Combo Box to a Flash MX DataGrid, so that only the products for
the selected category display on the grid. You will then modify column
headers, set default widths, and make some columns invisible.
Steps
1. In Flash MX, open RemoteDatagrid_raw.fla in the war directory.
2. Save it as RemoteDatagrid.fla in the war directory.
Linking the Combo Box to the Datagrid
3. Open the Actions panel for frame 1 of the Actions layer (press F9).
4. Examine the code. It should be very similar to the previous widget,
since the Categories ComboBox has the same handler functions as
before, namely the responder and the change handler.
5. Implement the getProductsByCategory_result() responder function
such that it populates the datagrid with the rows retrieved by the
remote call, as follows:
Inside the function, remove any existing items in the DataGrid by
calling its removeAllItems() method.
The recordset received from the remote call is already in the
format that the Flash DataGrid expects it: every object has
property names that can be references. Just invoke the
setDataProvider() method on the datagrid passing result as the
input :
product_dg.setDataProvider(result);
Here is the completed code for your reference:
function getProductsByCategory_result(result) {
product_dg.removeAllItems();
product_dg.setDataProvider(result);
}
6. Test the movie (Cntl + Enter). You should see all the data retrieved for
all the products in the “snow” category.
Formatting Columns on the Datagrid
In order to hide columns, provide headers, and resize the widths of the
columns, you must format the DataGrid using methods of this class. The
following steps accomplish this:
7. Position the cursor at the bottom of the code, under any existing code.
8. Create a reference called name_col.
Comentários a estes Manuais