dcsimg
A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: Tree component help

  1. #1
    Junior Member
    Join Date
    Dec 2004
    Location
    U.S.A.
    Posts
    6

    Tree component help

    Hi, I'm trying to make a news archive on my band website using the tree component and populating it with XML. Then, when a news item is clicked in the tree, it would display the text from the file in a text area on the stage. I managed to get the XML worked out via a tutorial, but I have no clue how to display the text. Can someone please help me? Thanks and peace.

    Brehnan

  2. #2
    Moderator whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755
    So.. you do or do NOT have the TREE Component populated??


    and how does this post relate to this one:
    http://board.flashkit.com/board/showthread.php?t=759950

    (at all?)

    Im curious as to what your stuck on? are you trying to add an onClick event to the objects on your TREE? so when clicked on they display some text?

  3. #3
    Junior Member
    Join Date
    Dec 2004
    Location
    U.S.A.
    Posts
    6

    TREE component

    Well, first of all, this post is not related to the other post at all. They are two separate sections of the website. I am stuck on what you described with the onClick event. Do you think you might be able to help me out? Thanks.

    Brehnan

  4. #4
    Moderator whispers's Avatar
    Join Date
    Mar 2001
    Location
    CFA2h (respect the HEX)
    Posts
    12,755
    You need to add a listener to your tree, that 'listens' for the tree object event 'change'


    here is an example:


    PHP Code:

    var myXML:XML = new XML();
    myXML.ignoreWhite true;
    myXML.onLoad = function(success:Boolean):Void  {
        
    // handle the XML received
        
    if (!success) {
            
    trace("Error loading XML");
        }
        else {
            
    trace("DONE");
            
    //trace(this);
            
    trace("XML TO LOAD: " myXML);
            
    first_tr.dataProvider myXML.firstChild;
            
    //first_tr.setIsBranch(first_tr.getTreeNodeAt(0), true);

        
    }
    };
    myXML.load("tree.xml");


    // Create Listener Object.
    var treeListener:Object = new Object();
    treeListener.change = function(event_obj:Object) {
        
    trace("File chosen name: " event_obj.target.selectedNode.attributes.label);
        var 
    isBranch:Boolean first_tr.getIsBranch(event_obj.target.selectedNode);
        
    trace("Branch: " isBranch);
    };
    // ------------------- add tree listener-------------------------------//
    first_tr.addEventListener("change"treeListener); 
    XML used in demo:

    Code:
    <data>
    	<file label="Archive 1" />
    	<file label="Archive 2" />
    	<file label="Archive 3" />
    	<file label="Archive 4" />
    	<file label="Archive 5" />
    </data>

  5. #5
    Junior Member
    Join Date
    Dec 2004
    Location
    U.S.A.
    Posts
    6
    Okay, when I click on the object inside the folder in the tree, I want it to open an external text file in a text field right next to the tree. I wasn't able to figure out how to make that happen with the info you posted. I'm pretty new to this sort of stuff, so could you help me understand this a bit better? Thanks a ton. Peace.

    Brehnan

  6. #6
    Member
    Join Date
    Aug 2004
    Location
    UK
    Posts
    88
    you know what - i reckon youre coming at this from the wrong direction - so - from the top level, youre wanting a content managed area of the web site? can you feed in somthing like this? :

    Code:
    <archive>
        <article>
            <title>Archived article 1</title>
            <content>Some content text</content>
        </article>
        <article>
            <title>Archived article 2</title>
            <content>Some content text</content>
        </article>
    </article>
    use the code i gave you on http://board.flashkit.com/board/showthread.php?t=759950 as a basis, from here you could parse it like this -

    create an archive movie clip that loads the archive xml file - its parse element function should look like this -

    Code:
    this.ParseElement = function(node)
    {	
         switch(node.nodeName) {
    		 
    		case "article":
    			this.attachMovie("archive_nav", "archive_nav"+this.getNextHighestDepth(), this.getNextHighestDepth(), {_x: this.X, _y:this.Y, node: node});
    			this.Y+= this.Yoff;
    		break;				 				
         }
    }
    create an archive_nav movieclip in the same way that i created the gig movieclip in the example, the above parse element function passes a reference to the whole archive xml node to the archive_nav clip. so you need to get the archive_nav movieclip to parse its own node. its parse element function should look like this -

    Code:
    this.ParseElement = function(node)
    {	
         switch(node.nodeName) {
    		 
    		case "title":
    			this._title = node.firstChild;
    		break;	
    		case "content":
    			this._content = node.firstChild;
    		break;	
    			 				
         }
    }
    then give it onPress event -

    Code:
    this.onPress = function(){
        _root.title = this._title; // _root.title being a textbox on the root with a var set to title.
        _root.content = this._content;  // _root.content being a textbox on the root with a var set to content.
    
    }

    hope that makes sense!? these are pretty hardcore concepts - it took me ages to get my head round them properly. youve just got to sit n think about it about it for a while, do some experiments and try and prove things incrementally... this is how i would do it anyway - let me know how you get on.
    http://robotnic.co.uk/
    -----------------------------------------

  7. #7
    FK'n_dog a_modified_dog's Avatar
    Join Date
    Apr 2003
    Location
    "aaarf"
    Posts
    9,176
    PHP Code:
    // on stage -
    // Tree component - instance name - first_tr
    // TextArea component - instance name - ta

    var myXML:XML = new XML();
    myXML.ignoreWhite true;
    myXML.onLoad = function(success:Boolean):Void {
    if(
    successfirst_tr.dataProvider myXML.firstChild
    };
    myXML.load("tree.xml");

    var 
    treeListener:Object = new Object();
    treeListener.change = function(event_obj:Object) {
    trace(event_obj.target.selectedNode.attributes.data);
    txtFile event_obj.target.selectedNode.attributes.data;
    loadTxt(txtFile);
    };
    first_tr.addEventListener("change"treeListener); 

    function 
    loadTxt(file){
    var 
    lv:LoadVars = new LoadVars();
    lv.load(file);
    lv.onLoad = function(success:Boolean):Void {
    if(
    successta.text this.txt// populate the TextArea component
    };
    }; 
    in tree.xml -
    Code:
    <data>
    	<file label="Archive 1" data="t1.txt" />
    	<file label="Archive 2" data="t2.txt" />
    	<file label="Archive 3" data="t3.txt" />
    	<file label="Archive 4" data="t4.txt" />
    	<file label="Archive 5" data="t5.txt" />
    </data>
    in t1.txt file -
    Code:
    &txt=this is a test&
    hth

  8. #8

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