Friday, March 19, 2010    
Home My Books Blog ColdFusion About Me Back    

Calendar
<< Jan 2004 >>
S M T W T F S
        1 2 3
4 5 6 7 8 9 10
11 12 13 14 15 16 17
18 19 20 21 22 23 24
25 26 27 28 29 30 31
             

Search

Categories
 • Acrobat (3) [RSS]
 • Adobe (90) [RSS]
 • AdobeMAX06 (45) [RSS]
 • AdobeMAX07 (59) [RSS]
 • AdobeMAX08 (66) [RSS]
 • AdobeMAX09 (39) [RSS]
 • AdobeMAX10 (1) [RSS]
 • AIR (219) [RSS]
 • Appearances (191) [RSS]
 • Books (72) [RSS]
 • CFEclipse (15) [RSS]
 • ColdFusion (1381) [RSS]
 • Data Services (34) [RSS]
 • Fish Tank (5) [RSS]
 • Flash (197) [RSS]
 • Flex (498) [RSS]
 • Home Automation (5) [RSS]
 • Jobs (116) [RSS]
 • JRun (14) [RSS]
 • Labs (43) [RSS]
 • LiveCycle (34) [RSS]
 • MAX (232) [RSS]
 • Mobile (120) [RSS]
 • Regular Expressions (17) [RSS]
 • RIA (21) [RSS]
 • SQL (40) [RSS]
 • Stuff (536) [RSS]
 • Tips (CF Studio) (80) [RSS]
 • Tips (CF) (795) [RSS]
 • Tips (Dreamweaver) (91) [RSS]
 • Tips (Flex Builder) (2) [RSS]
 • Using CF (162) [RSS]

Other BLOGs
 • Charlie Arehart
 • Lee Brimelow
 • Ray Camden
 • Christophe Coenraets
 • Sean Corfield
 • Mihai Corlan
 • Cornel Creanga
 • Mark Doherty
 • John Dowdell
 • Danny Dura
 • Enrique Duvos
 • Steven Erat
 • Kevin Hoyt
 • Serge Jespers
 • Adam Lehman
 • Duane Nickull
 • Miti Pricope
 • Andrew Shorten
 • Ryan Stewart
 • James Ward
 • Greg Wilson
 • Full As A Goog

RSS Feeds
 • Feed
 • Subscribe

Join my mailing list and find out about new books and other topics of interest.

Thoughts, ideas, tips, musings, and pontifications (not necessarily in that order) by Ben Forta ...
NOTE: This is my personal blog, and the opinions and statements voiced here are my own.

Viewing By Day : January 5, 2004 / Main
January 5, 2004

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<src.length; recNo++) {
// Get record
rec=src.getItemAt(recNo);

// Is in same category as previous?
if (categElement.attributes["label"] != rec["CATEGORY"]) {
// If not, add new category node
categElement = tree.createElement("node");
categElement.attributes["label"] = rec["CATEGORY"];
categElement.attributes["url"] = "";
tree.appendChild(categElement);
itemCount=0;
}

// Add this item
childElement = tree.createElement("node");
childElement.attributes["label"] = rec["LABEL"];
childElement.attributes["url"] = rec["URL"];
childElement.attributes["description"] = rec["DESCRIPTION"];
categElement.appendChild(childElement);
categElement.attributes["description"]=++itemCount + " selections";
}

// Return complete XML tree
return tree;
}

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.

TrackBacks
There are no trackbacks for this entry.

No trackback URL. Trackbacks are only allowed via interactive form.

Comments

  © Copyright 1997-2009 Ben Forta, All Rights Reserved