There's certainly a bug in here, but you can try replacing the
appendChild call:
> var newNodeAdded:XML = selectedNode.appendChild(newItem);
with:
selectedNode.insertChildBefore(null, newItem);
Also, I changed selectedNode to type XML from Object.
This works for me, the Tree see's the update and converts the leaf to a
closed branch with the new node.
Let me know if you'll still have problems.
-Michael
--- In [email protected], "sufibaba" <[EMAIL PROTECTED]> wrote:
>
> Hi Matt,
>
> The node has not been added anywhere else. I've modified the Tree
> example from the Flex Sample Explorer to duplicate the problem I am
> having in my App and it is exhibiting the same behavior.
>
> ------------- tree.mxml --------------------------------------------
>
> <?xml version="1.0" encoding="utf-8"?>
>
> <mx:Application xmlns:mx="http://www.macromedia.com/2005/mxml"
> creationComplete="srv.send()">
>
> <mx:Script>
> <![CDATA[
>
> [Bindable]
> public var selectedNode:Object;
>
> [Bindable]
> public var XLC:XML;
>
> public function initList(event:Event)
> {
> XLC = event.target.result;
> }
>
> public function treeChanged(event:Event) {
> selectedNode=Tree(event.target).selectedNode;
> }
>
> public function addNewNode() //
> {
> //var myXML:XML = model.templateLayout.treeData;
>
>
> var newItem:XML = <node label="new node"/>
>
> var newNodeAdded:XML = selectedNode.appendChild(newItem);
> //Alert.show ("Tree changeEvt : " + newNodeAdded.toXMLString());
> selectedNode = newNodeAdded;
>
> myTree.selectedNode = selectedNode;
> }
>
>
>
> ]]>
> </mx:Script>
>
> <mx:HTTPService id="srv" url="../assets/tree.xml" resultFormat="e4x"
> result="initList(event)"/>
>
> <mx:Button label="addnewnode" id="newadd" click="addNewNode()" />
>
> <mx:HDividedBox width="100%" height="100%">
> <mx:Tree id="myTree" width="50%" height="100%" labelField="@label"
> rootVisible="false" dataProvider="{XLC}"
> change="treeChanged(event)"/>
> <mx:TextArea height="100%" width="50%"
> text="Selected Item: [EMAIL PROTECTED]"/>
> </mx:HDividedBox>
>
> </mx:Application>
>
>
> -------- assets/tree.xml ------------------------------------
>
> <?xml version="1.0" encoding="utf-8"?>
> <node>
>
> <node label="Mail Box">
> <node label="Inbox">
> <node label="Marketing"/>
> <node label="Product Management"/>
> <node label="Personal"/>
> </node>
> <node label="Outbox">
> <node label="Professional"/>
> <node label="Personal"/>
> </node>
> <node label="Spam"/>
> <node label="Sent"/>
> </node>
>
> </node>
>
> -------------------------------------------------------------
>
> I tried both IE and Firefox on winXP and this bug crashes both
> browsers when a new node is appended to a leaf node.
>
> Is there a possible work around for this bug do you think?
>
> Cheers,
>
> Tim
>
--
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/
<*> 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/