Hi All,
i've search a lot for a solution in keeping my Tree state after a data 
refresh and now, finally at all i reached my scope.

This is my solution:
my data provider in an xml like this
<root>
    <Agent label="one" id="">
       <Agent label="one-1" id="1"/>
       <Agent label="one-2" id="2"/>
   </Agent >
    <Item label="two" id="">
       <Item label="two-1" id="3"/>
       <Item label="two-2" id="4"/>
   </Item >
</root>

i don't set the myTree.dataprovider equal to an HTTPService.lastResult, 
but i set it by hand aftar some modification of the xml.
so, when i retrieve the new xml i chek the myTree.openItems object to 
manage my NEW xml and add the attribute open="true" to the opened node.
I get the rigth node checking the node.LocalName() and some other 
attributes. after this process i change my data provider and i set the 
render variable to true

myTree.dataProvider = xml.
render = true;

in the myTree item i've set the "render" event, so after the tree is 
designed, the event is dipatched and i can open my nodes parsing the new 
xml.


this is my as code:
--MXML--
<mx:Tree id="menu" height="100%" width="100%" borderStyle="none" 
columnWidth="200"
    horizontalScrollPolicy="auto" verticalScrollPolicy="auto"
    showRoot="false"
    itemRenderer="myMenuTreeItemRenderer"
    labelField="@label"
    click="showPopupMenu(event)"
    render="renderFunc()"/>

--Action Script--
private function srvResult():void{
     xml = XML(srv.lastResult); //The HTTPService result
    //set open=true for open nodes
    for(var i:Object in menu.openItems){
        for each(var node:XML in xml.descendants()){
            if(node.localName() == menu.openItems[i].localName()){
                if( ([EMAIL PROTECTED] != "" && [EMAIL PROTECTED] == 
[EMAIL PROTECTED]) || ([EMAIL PROTECTED] == "" && [EMAIL PROTECTED] == 
[EMAIL PROTECTED]) ){
                    [EMAIL PROTECTED]"true";
                }
            }
        }
    }   
     menu.dataProvider=xml;
     render=true;
 }
var render:Boolean = false;

public function renderFunc():void{
     if(render){
         //apro i nodi
        for each(var node:XML in xml.descendants()){
            if(menu.dataDescriptor.isBranch(node)){
                if([EMAIL PROTECTED] == "true"){
                    menu.expandItem(node,true);
                }
            }
        }
    }
    render=false;
}

bye Federico
Chiacchiera con i tuoi amici in tempo reale! 
 http://it.yahoo.com/mail_it/foot/*http://it.messenger.yahoo.com 


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

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/flexcoders/

<*> Your email settings:
    Individual Email | Traditional

<*> To change settings online go to:
    http://groups.yahoo.com/group/flexcoders/join
    (Yahoo! ID required)

<*> To change settings via email:
    mailto:[EMAIL PROTECTED] 
    mailto:[EMAIL PROTECTED]

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 



Reply via email to