A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: Tree component with XML - Serious problem!

  1. #1
    Junior Member
    Join Date
    Jun 2005

    Tree component with XML - Serious problem!

    I just came from a bookstore where I spent 3 hours searching for this solution (in addition to several days trying to find info on this online). I posted on several forums but still either no response or a non-working solution. Either this is impossible to do or nobody really knows!

    Here's what I need to do. It's quite a simple concept, but I'm not very familiar with AS 2 or XML:

    1. I'm making a Flash application where the Tree component is populated with data from an XML file. So far so good.

    2. The XML data contains several root categories, each with about 10 child nodes. (The categories are music categories like Rock, Pop, Jazz...)

    3. When the user clicks on Jazz for example, the category would list the relevant music tracks inside that category (like Jazz 1, Jazz 2, and so on).

    4. When user clicks on Jazz 1, an external .swf movie (named rock1.swf) would start playing inside another movieclip on stage.

    That's all. I figure this should be incredibly simple for someone familiar with AS.

    Here's part of my XML file:
    <node label="Rock 1" data="rock1.swf">

    And here's the AS code:

    musicTreeDP = new XML();
    musicTreeDP.ignoreWhite = true;
    musicTreeDP.onLoad = function() {
    musicTree.dataProvider = musicTreeDP;
    musicTreeListener = new Object();
    musicTreeListener.change = function(evtObject) {
    url = evtObject.target.selectedNode.attributes.data;
    musicTree.addEventListener("change", musicTreeListener);

    What happens with the above code is that I keep getting "undefined" as the url whenever I click on ANY node in the tree (including root). I need the click to be detected only for the leaf node (firstChild?).

    I'm thinking something needs to be changed in this line but I could be wrong:
    url = evtObject.target.selectedNode.attributes.data;

    How do you define that file "rock1.swf" should start playing?

    Does anyone how to do this?


  2. #2
    Senior Member
    Join Date
    Sep 2000

    The Tree extends the List class so where you have "selectedNode" it should be "selectedItem". You won't see selectedItem under the Tree help but if you pull up "List" in the help files you'll see more information about it...

    musicTreeListener.change = function(evtObject) {
    	var node = musicTree.selectedItem;
    	if (!musicTree.getIsBranch(node)) {
    		url = evtObject.target.selectedItem.attributes.data;
    		trace("URL = "+url)

    hope this helps,

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Click Here to Expand Forum to Full Width

HTML5 Development Center