tailieunhanh - Flash Builder 4 and Flex 4 Bible- P14

Flash Builder 4 and Flex 4 Bible- P14: When Macromedia first released Flash MX in 2002, the product was branded as the new way to build Rich Internet Applications (known by the acronym RIA). The term was invented at Macromedia to describe a new class of applications that would offer the benefits of being connected to the Internet, including access to various types of Web-based services, but would solve many of the nagging issues that had been inherent in browser-based applications since the mid-1990s | Chapter 20 Using Advanced List Controls On the Web The code in Listing is available in the Web site files as in the chapter20 project. Figure shows the resulting application with formatted phone numbers in the last column of the DataGrid control. FIGURE A DataGridColumn with custom label formatting Using a dynamic data field As I described previously the custom formatting function for a DataGridColumn requires an argument that references the DataGridColumn that is calling the function. The purpose of this argument is to enable you to determine the data field of the current data item dynamically. For example if the data provider s data items have phone values in two different properties and you want to format them both with the same logic you can identify the property you want to format with the array-style expression item . The dataField property of the DataGridColumn returns the name of the property currently being processed so you need only one custom function to format as many data properties as needed private function getPhoneLabel item Object column DataGridColumn String var dataValue String item var pattern RegExp - g var phoneValue String pattern return phoneValue 621 Part III Working with Data Debugging a custom formatting function It can be instructive to add a trace statement to the body of a custom formatting function. As you scroll up and down in a DataGrid the trace statement in the custom function is executed each time the data grid column has to be formatted private function getPhoneLabel item Object column DataGridColumn String var dataValue String item var pattern RegExp - g var phoneValue String pattern trace original value dataValue formatted value phoneValue return phoneValue Figure shows the resulting output in Flash Builder s Console view when the application is