First time here? First time here? Newsletter Signup Newsletter
Search tutorials
Author: Ben Johnson

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,
					  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’
	DataGlue.bindFormatStrings( employeesChart,
					 “#FirstName# #LastName#”,
 “#MonthsWithCompany#” )

» Level Intermediate

Added: 2002-08-16
Rating: 7 Votes: 20
(10 being the highest)
» 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.
» Forums
More help? Search our boards for quick answers!


  • There are no comments yet. Be the first to comment!

  • You must have javascript enabled in order to post comments.

Leave a Comment
  • Your email address will not be published. All fields are required.
Featured Flash FLA
» Author: Inocreato
» Title: RaiseTheBlocks
» Description: Raise all the blocks to win the game
Featured Sound Loops
Image for equalize

Audio Player

» Author: TomCat Carty
» Title: The Wood
» Description: Just a little game ending or it can maybe be looped. Recorders with music box and percussion to give the feel of well, I don't know, the woods? Free to use, just credit me. thank you
Latest Font
» Author: Fábio FAFERS
» Description: I created this font for free use. Everyone can apply it in personal or business texts. Its free, but I want to be communicated in case of business use. Donations are accepted to keep the project of free fonts alive! Thank you all
Featured Sound Fx
Image for equalize

Audio Player

» Author: Davisigner
» Description: Hmm... what to say about this one? It's reminiscent of the closing notes of the opening music from the Three Stooges done in a church organ style with a closing cymbal crash. I'll give this one away gratis, but feel free to check out my free loops and potential upcoming license-mandated ones over in the respective part of Flashkit.