Hi there, I'm somewhat new at this.  I'm trying to add a leaf to a tree control and have the new node automatically selected.  My code works the first few times, but then it starts to select strange locations.  Any ideas why?
 
You can try it here
 
 
Thanks!!
Rob
 

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml "
 layout="absolute" xmlns:ns1="html-template.*" xmlns:ns2="components.*" >
 
 <mx:Script>
        <![CDATA[
         import mx.logging.AbstractTarget;
            import flash.events.*;
            import mx.events.*;
            import mx.controls.*;
      import flash.net.URLLoader;
      import flash.net.URLLoaderDataFormat;
      import flash.net.URLRequest ;

   private var directory;

   private function treeComplete(event:Event):void {
    
   }

            private function changeEvt(event:Event):void {
              
               if ( [EMAIL PROTECTED] == true) {
                    directory = Tree(event.target).selectedItem;
                }
               else  if ( [EMAIL PROTECTED] == false){
                 directory = Tree(event.target).selectedItem.parent();
               }              
            }

 
   /**** New File Button Handler *****/
   private function newFile():void {
    
    //create file
    var new_file:Object = directory.appendChild(<Pfolder label="New File" isBranch="false"/>);     
    if([EMAIL PROTECTED] == true)    //open folder automatically so you can see the new file
     tree1.expandItem (directory, true, true, false);
   
    //????? Trying to get new file selected automatically--Not working
    var length:int = new_file.children().length();
    tree1.selectedItem = new_file.children()[length - 1];
    trace("--\n\n" + new_file + "\n\n" + new_file.children() + "\n\n" + new_file.child(0));
   }     
    ]]>
 </mx:Script>
 
 
 
 
 <mx:XML source="file_list.xml" id="stuff"/>
 <mx:Tree labelField="@label" x="18.5" y="10" width="153" height="192" id="tree1" editable="false"
        change= "changeEvt(event);"
        creationComplete="treeComplete(event)" >
   <mx:dataProvider>
   {stuff}
   </mx:dataProvider>    
 </mx:Tree>
 
 
 <mx:Button x="18.5" y="210" label="New File" click="newFile()" id="btnNewFile" enabled="true"/>
 
</mx:Application>

 

Here's the XML "file_list.xml":
 

<?xml version="1.0" encoding="utf-8"?>

<folder label="Mail" isBranch="true">

<folder label="INBOX" isBranch="true"/>

<folder label="Personal Folder" isBranch="true">

<Pfolder label="Business" isBranch="false"/>

<Pfolder label="test" isBranch="false"/>

<Pfolder label="Personal" isBranch="true" />

<Pfolder label="Saved Mail" data="" blah blah" isBranch="true"/>

</folder>

<folder label="Sent" isBranch="true"/>

<folder label="Trash" isBranch="true"/>

</folder>


 
__._,_.___

--
Flexcoders Mailing List
FAQ: http://groups.yahoo.com/group/flexcoders/files/flexcodersFAQ.txt
Search Archives: http://www.mail-archive.com/flexcoders%40yahoogroups.com





SPONSORED LINKS
Software development tool Software development Software development services
Home design software Software development company

Your email settings: Individual Email|Traditional
Change settings via the Web (Yahoo! ID required)
Change settings via email: Switch delivery to Daily Digest | Switch to Fully Featured
Visit Your Group | Yahoo! Groups Terms of Use | Unsubscribe

__,_._,___

Reply via email to