I try create general rule for creating editors for xml trees. I realize 
DnD on List in my example code. I found that my XMLListCollection not 
dispatch events if i reorder items. My example code works if i manual 
trigger dispatching. If I uncomment line //dispatchEvent(new 
Event("propertyChange")) event event are dispatched two ones on one DnD 
operation that pollute collection with duplicates. Anybody show me 
proper way, maybe my idea with collections and binding is wrong?
Result: http://81.21.200.136/public/BindingInTrees.swf
My code:
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"; 
xmlns:local="*" creationComplete="evCreationComplete()">
    <mx:Script>
        <![CDATA[
            import mx.binding.utils.BindingUtils;
            import mx.collections.XMLListCollection;
            private var xml:XML=<items>
                <item label="item 1"/>
                <item label="item 2">
                    <subitems>
                        <subitem label="subitem 1"/>
                        <subitem label="subitem 2"/>
                    </subitems>
                </item>
                <item label="item 3">
                    <subitems>
                        <subitem label="subitem 3"/>
                        <subitem label="subitem 4"/>
                    </subitems>
                </item>
            </items>;
            [Bindable]
            private var xmlListCol:XMLListCollection;
            [Bindable]
            private var xmlListCol2:XMLListCollection;
            private function evCreationComplete():void{
                var xL:XMLList=new XMLList(xml.item)
                xmlListCol=new XMLListCollection(xL)
                
BindingUtils.bindSetter(evSubsChange,subsEditor,"xmlListCol")
            }
            private function evSubsChange(v:XMLListCollection):void{
                if(list1.selectedItem is XML){
                    
XML(xmlListCol.getItemAt(list1.selectedIndex)).replace(0,new 
XML("<subitems>"+v.toXMLString()+"</subitems>"))
                }   
            }
            private function evListSelChange():void{
                var xL:XMLList=new 
XMLList(XML(list1.selectedItem).subitems.subitem)
                xmlListCol2=new XMLListCollection(xL)
            }
       
        ]]>
    </mx:Script>
    <mx:HBox>
        <mx:List
            id="list1"
            dataProvider="{xmlListCol}"
            change="evListSelChange()"
            labelField="@label"
            dragEnabled="true" dropEnabled="true" dragMoveEnabled="true"
            width="100"
            height="200"
            />
        <local:TreeSubitemsEditor id="subsEditor" 
xmlListCol="{xmlListCol2}"/>
    </mx:HBox>

</mx:Application>

and component: TreeSubitemsEditor.mxml

<?xml version="1.0" encoding="utf-8"?>
<mx:VBox xmlns:mx="http://www.adobe.com/2006/mxml"; >
    <mx:Script>
        <![CDATA[
            import mx.events.CollectionEvent;
            import mx.collections.XMLListCollection;
            private var _xmlListCol:XMLListCollection;
            [Bindable]
            public function set xmlListCol(v:XMLListCollection):void{
                _xmlListCol=v
                
xmlListCol.addEventListener(CollectionEvent.COLLECTION_CHANGE,evColChange)
               
            }
            public function get xmlListCol():XMLListCollection{
                return _xmlListCol
            }           
            private function evColChange(e:CollectionEvent):void{
                trace("evColChange")
                //dispatchEvent(new Event("propertyChange"))
            }
        ]]>
    </mx:Script>
    <mx:HBox>
        <mx:List
        id="list0" dataProvider="{xmlListCol}"
        labelField="@label"
         dragEnabled="true" dropEnabled="true" dragMoveEnabled="true"
             width="100"
            height="200"
         />
         <mx:TextInput id="changeLabelTI"
             visible="{list0.selectedIndex>-1}"
             text="{xmlListCol.getItemAt(list0.selectedIndex)[EMAIL PROTECTED]"
             
change="xmlListCol.getItemAt(list0.selectedIndex)[EMAIL 
PROTECTED];list0.invalidateList()"
             toolTip="change subitem label"
             />
    </mx:HBox>
         <mx:Button label="manual dispatch event" 
click='dispatchEvent(new Event("propertyChange"))' />
</mx:VBox>

-- 
Robert Was





--
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