I would not assign an XMLList to selectedItem.  I would extract the XML
node from the XMLList.  It is a bug that we don't extract the node
correctly so feel free to file a bug if you want.

 

                categoryComboBox.selectedItem =
myCollection.child('categories').children().(@id == "0")[0];



 

________________________________

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

 

Hi,

preventDefault() works fine, thanks a lot Alex! 

On to the <mx_internal_uid> mystery node then...

The problem only occurs when I set the selectedItem of the ComboBox but
can't see why that should present this problem?

[artistdata.xml]

<artistdata>
    <categories>
        <category id="0">
            <label>Photographers</label>
        </category>
        <category id="1">
            <label>Stylists</label>
        </category>
    </categories>
</artistdata>

[mxnode.mxml]

<?xml version="1.0" encoding="utf-8"?>
<mx:Applica! tion xmlns:mx="http://www.adobe.com/2006/mxml";
layout="absolute" initialize="onInitialize()">
<mx:HTTPService url="artistdata.xml" id="myService"
result="onResult(event)" resultFormat="e4x">
    
</mx:HTTPService>
    <mx:Script>
        <![CDATA[
            import mx.events.ListEvent;
            import mx.rpc.events.ResultEvent;
            import mx.collections.XMLListCollection;
            
            [Bindable]
            public var myCollection:XMLListCollection;
    
     &n! bsp;      private function onInitialize():voi d
            {
                myService.send();
            }
                        
            private function onChange(p_evt:ListEvent):void
            {
                trace(myCollection.child('categories').children());
            }
                
            private function onResult(p_evt:ResultEvent):void
          &n! bsp; {
                var XMLListData:XMLList = new XMLList(p_evt.result as
XML);
                myCollection = new XMLListCollection(XMLListData);
                categoryComboBox.selectedItem =
myCollection.child('categories').children().(@id == "0");
            }
        ]]>
    </mx:Script>

    <mx:ComboBox id="categoryComboBox"
dataProvider="{myCollection.child('categories').children()}"
change="onChange(event)"></mx:ComboBox>

</mx:Application>


--- In [email protected], "Alex Harui" <[EMAIL PROTECTED]> wrote:
>
> Your itemEd! itEnd handler should call preventDefault() and maybe
&! gt; dest royItemEditor
> 
> 
> 
> ________________________________
> 
> 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>
> <folde! r 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 (n! ode == 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()">
&! gt; <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 = ne! w XMLListCollection(XMLListData);
> ! }
& gt; 
> 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