A Flash Developer Resource Site














Internet Commerce

Partners & Affiliates














Developer Channel

internet.com


Featured Flash FLA
Gallery Downloads 11337 Flash Movies | 1 New Flash Movies Added
What's New | Top 100

Featured FLA

» Author: Bugra Ozden
» Title: Skatalog v9 - product catalog
» Description: Create your product catalog easly and publish on your website or Create your image gallery, documents list, portfolio. Fully XML Driven
» More by Bugra Ozden


Random FLAs | Add Flash Movie
Featured Flash Site
Gallery Downloads 5828 Flash Sites | 0 New Flash Links
What's New | Top 100 Flash Site

Featured Site

» Posted in the Flash Kit Links section
» Title: Creative DW Image Show PRO
» Description: Creative DW Image Show PRO is a Dreamweaver extension which enables the user to create multimedia presentations. It combines the features of the popular Creative DW Image Show with the ability to add professional text effects to slides (similar to After Effects). The product is very customizable: the user can choose the duration of the transition effects, the slide motion start and end position, zoom and panning type for both images and texts.


Random Links | Add your own Flash Related Links
Flash Tutorials 1280 Tutorials 7 New Tutorials Added!
What's New | Top100

» Make a Flash Slide Show Screen Saver
» Simple flash making tutorial for thanksgiving
» Create flash banner for website
» Create xml slideshow with free template
» How to Insert a Multilingual Subtitle Into Your Flash Video Studio
» How to Create Cool Halloween Slideshow
» Debugging flash using the Firebug console
» Create Flash Slideshow on Blogger
» FLASH TRICKS IN WEB ADVERTISING: FLASH BANNERS
» Unknown Tag: Title10
Random Tutorial | Add Site

Sr Instructional Designer D2L-Moodle,Clearance
WSI Nationwide, Inc.
US-NJ-Fort Monmouth

Justtechjobs.com Post A Job | Post A Resume


Tutorials Home What's New Top Rated Submit myTutes Random!

Search Tutorials


Tutorials Tutorials » Backend

Categories Data Binding in Flash MX
Author: Ben Johnson

 
Page 3
«prev 1 2 3 4 next»

Fine Tuning Your Output

Our employee list box display showed us an example of a simple data transformation. However, there are many instances when we need to really do something to our data. Perhaps you need to convert your data from feet to miles or days to weeks. For the Employee Management application, we decide that we want to display how many years our employees have been with the company. Unfortunately, the data is stored in months and the bindFormatStrings() cannot process complex data transformations, such as addition and multiplication.

Fortunately there’s another data binding function of DataGlue, bindFormatFunction(). This function will allow us to have more granular control as to how our data is formatted. Instead of passing two formatting strings, we pass a reference to a user-defined function that will control all the formatting. The function definition is shown below:

bindFormatFunction( component, recordset, referenceToFunction )

In Listing 3, our callback function now calls bindFormatFunction() and passes the function reference for a user-defined function called myFormattingFunction().

Listing 3
// getAllEmployees_result (callback function)
//
function getAllEmployees_Result (result) {
 DataGlue.bindFormatFunction( employeesChart,
 result,
 myFormattingFunction )
}
// myFormattingFunction (user-defined formatting function)
//
// This function is called for each individual row of data
// in the recordset.
//
function myFormattingFunction (record) {
 // create an object to return to the component for each
 // row of data
var returnObj = new Object();
 // Note that you must return an object with Label &
 // Value attributes, but UI components require an object
 // with Label & Data attributes.
 returnObj.label = record.firstName
 returnObj.value = Int(record.monthsWithCompany/12 * 100) / 100;
 return returnObj;
}

Behind the scenes, DataGlue loops through the recordset and calls the myFormattingFunction for each row. The record argument contains all the data for the current row being processed. Each column can be accessed by its column name so the data in FirstName column for that row can be accessed as record.firstName.

Also note that the return object can vary. The UI components (ListBox, Tree, etc) accept a return object with a Label attribute for the label field and a Data attribute for the data field. The Charting components, on the other hand, accept an object with a Label attribute for the label field and a Value attribute for the value field. You can change what field the value is assigned to by using the setValueSource() method of the Chart components. This is required when using bindFormatStrings() with Chart components. See Listing 4 shows an example of using bindFormatStrings() with Charting Components.

Listing 4
// getAllEmployees_result (callback function)
//
function getAllEmployees_Result (result) {
 // set Value field to ‘data’
 employeesChart.setValueSource(“data”);
 DataGlue.bindFormatStrings( employeesChart,
 result,
 “#FirstName# #LastName#”,
 “#MonthsWithCompany#” )
}

«prev 1 2 3 4 next»

» Level Intermediate

Added: : 2002-08-16
Rating: 6.48 Votes: 19
Hits: 1663
» Author
Ben Johnson has been programming for seven years and creating web applications for the past two years. He is currently an information architect for Architekture.com, creating web applications using Flash and ColdFusion.
» Download
Download the files used in this tutorial.
Download (0 kb)
Get conversion and unzipping tools for PC and Mac here!

» Forums
More help? Search our boards for quick answers!

Please rate this tutorial, 10 is the top rating, you can also click the comments link to read/write a review.
10 9 8 7 6 5 4 3 2 1
Read or Post Comments
 
   
 

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs