ActionScript Code Used in Flex Example

A few of you asked to see the ActionScript code use to implement the query2tree() function used in the Flex example I posted last week. So, here it is:
function query2tree(src) {
// Define tree object
var tree:XML = new XML();
// Define vars
var recNo:Number, itemCount:Number;
var rec:Object;
var categElement:XMLNode, childElement:XMLNode;
// Loop through records
for (recNo=0; recNo
expects XML containing the menu structure, and uses "label" as the display label. This function creates that structure based on the contents of a ColdFusion returned query, each row is an item, and any time the category changes a new "folder" is created. Very simple code, for a very simple one-level deep menu, and hard coded for my example, but it does the trick.
I've been going back and forth on whether or not my CFC should return the complete XML. There would probably be performance gains in doing so, but at the same time I think my CFC code needs to not be tied to any specific client technology (and Flex is a ColdFusion client here). The jury is still out on this one.

Leave a Reply