Sunday, April 29, 2007

Using Flash Component: TREE

Tree is a pretty cool component, i just am only exploring the surface of it. there are already some guide to it via macromedia support, most of the non-macromedia support pages actually charge money for the tutorial! anyways.. maybe theirs is very comprehensional. So here is my Starter guide to TREE.

If you have used MS Outlook you might be familiar with how it looks like, Below is the flash movie that we wil be creating:-

Link to the completed Tree

Steps to create the above:
1) Drag a tree component to stage and name the instance: "myTree"
2) create a dynamice text box and name the instance: "status_txt"
3) create a new layer and call it 'action' and well type the code below:-

//Tree
//create XML object
var myTreeDP:XML = new XML();
myTreeDP.ignoreWhite = true;
myTreeDP.load("data.xml");
//when XML is loaded send data to TREE
myTreeDP.onLoad = function() {
myTree.dataProvider = this.firstChild;
};
//create listener for tree,w hen click do the following
var treeListener:Object = new Object();
treeListener.change = function(evt:Object) {
selNode = evt.target.selectedNode
selNoteData = selNode.attributes.label
selNoteMessage = selNode.attributes.comment
if (selNoteMessage == undefined) {
selNoteMessage = ""
}
status_txt.text = selNoteData + " - " + selNoteMessage
};
//assign listener to tree.
myTree.addEventListener("change", treeListener);


4) Next you need the data file as the tree takes data from XML (it can take from the actionscript, but my example takes from XML) so launch Notepad and paste the following:-

i tried pasting my XML code here, DAMM blogger, makes the code hidden.. weird. anyways i wont leave you hanging, so here is a link to the data.xml file



5) save the xml file as data.xml in the same directory as your flash, save your flash, publish and preview and you get your tree.


what else to try?
i think the real trick about tree is how to apply it, im cracking my head thinging about this, how to use it for my work'place e-learning portal, seem like a good idea to make a simple 'internal' email application, but i suppose i need more time to figure this out. any suggestion.. do comment.

No comments: