Your itemEditEnd handler should call preventDefault() and maybe
destroyItemEditor

 

________________________________

From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of nikolajselvik
Sent: Friday, March 21, 2008 1:30 PM
To: [email protected]
Subject: [flexcoders] Re: 'label' & 'mx_internal_uid' nodes mysteriously
added to XMLListCollection

 

[artist.xml]

<artistdata>
    <artist>
        <name>John</name>
        <portfolio>
            <folder isBranch="false">
                <name>Johns Folder</name>
            </folder>
        </portfolio>
    </artist>
    <artist>
        <name>Anna</name>
        <portfolio>
            <folder isBranch="false">
                <name>Annas Folder</name>            </folder>
        </portfolio>
    </artist>
</artistdata>

[ArtistTreeDataDescriptor.as]

package 
{
    import mx.collections.ArrayCollection;
    import mx.collections.ICollectionView;
    import mx.collections.XMLListCollection;
    import mx.controls.treeClasses.DefaultDataDescriptor;

    public final class ArtistTreeDataDescriptor extends
DefaultDataDescriptor
    {
        public function ArtistTreeDataDescriptor()
        {
            super();
        }
        
&nbs! p;   override public function getChildren(node:! Object,
model:Object=null):ICollectionView
    {
        if (node == null)
        {
            return null;
        }
        
        var children:*;
        var childrenCollection:ICollectionView;
        
        if (node is XML)
        {
            if((node as XML).localName() == "artist")
            {
                children = node.portfolio.folder;
            }
    &nb! sp;   }
        
        if(children == undefined)
        {
            return null;
        }

        childrenCollection =  new XMLListCollection(children);

        return childrenCollection;
    }        
        
    }
}

[ArtistTree.mxml]

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml";
layout="absolute" initialize="onInitialize()">
<mx:HTTPService url="artistdata.xml" id="myService"
result="onResult(event)" resultFormat="e4x">
    
&l! t;/mx:HTTPService>
    <mx:Script>  ;       <![CDATA[
            import mx.events.ListEvent;
            import mx.rpc.events.ResultEvent;
            import mx.collections.XMLListCollection;
            
            [Bindable]
            public var myCollection:XMLListCollection;
    
            private function onInitialize():void
            {
                myService.send();    
            }
    &nb! sp;       
            private function onResult(p_evt:ResultEvent):void
            {
                var XMLListData:XMLList = new XMLList(p_evt.result as
XML);
                myCollection = new XMLListCollection(XMLListData);
            }
            
            private function onItemEditEnd(p_evt:ListEvent):void
            {
                p_evt.currentTarget.editedItemRenderer.data.name =
p_evt.currentTarget.ite! mEditorInstance.text;
      &! nbsp; &n bsp;       trace(myCollection);
            }
    
            private function
artistTreeLabelFunction(p_object:Object):String
            {
                var nodeXML:XML = p_object as XML;
                var label:String;
                
                switch(nodeXML.localName())
                {
                    case "artist":
        &n! bsp;           label = nodeXML.name;
                    break;        
                    
                    case "folder":
                    label = nodeXML.name;
                    break;
                }
                
                return label;
            }
  !           
  &! nbsp;         ]]>
    </mx:Script>
    <mx:Tree 
        labelFunction="artistTreeLabelFunction" 
        dataDescriptor="{new ArtistTreeDataDescriptor()}" 
        dataProvider="{myCollection.child('artist')}" 
        height="100%" 
        width="100%" 
        itemEditEnd="onItemEditEnd(event)"
        editable="true"
        ></mx:Tree>
</mx:Application>

Description:

Editing an item in the tree will result in <label> nodes getting added
to the artist node or folder node. Note that you need to edit an item
twice for this node to show up in the my! Collection trace.

 

Reply via email to