productData.category[0].insertChildBefore(x, y)
-----Original Message-----
From: [email protected] [mailto:[EMAIL PROTECTED] On
Behalf Of greenfishinwater
Sent: Thursday, April 20, 2006 12:00 PM
To: [email protected]
Subject: [flexcoders] Flex2B2 Problem with XML insertChildBefore
I am experimenting with using XML as the data provider for a tree. I
want to be able to inset new nodes at run time. I have successfully
used appendChild and insertChildAfter, but cannot get
insertChildBefore to work. In my example app I think I maybe setting
up the position where to insert incorrectly. Does anybody else have
experience of using these insert methods.
Also I would like to know how to insert a new node underneath an
existing node, rather than at the same level.
This is my app which is coded for Flex 2 beta 2
Thank you
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" xmlns="*"
layout="absolute">
<mx:Script>
<![CDATA[
import mx.collections.XMLListCollection;
import flash.events.*;
import mx.events.*;
import mx.controls.*;
[Bindable]
public var productData:XML = <food>
<category name="Fish">
<product name="Salmon"/>
</category>
<category name="Vegetable">
<product name="Carrot"/>
</category>
</food>;
public var extraData:XML = <category name="Fruit">
<product name="Orange"/>
</category>;
public var newFish:XML = <product name="Chilean Sea Bass"/>;
public function appendToEnd() : void
{
productData = productData.appendChild(extraData);
myTree.dataProvider = productData;
}
public function insertAfterFish() : void
{
var x:Object = productData.category[0];
var y:Object = extraData;
productData = productData.insertChildAfter(x, y);
myTree.dataProvider = productData;
}
public function insertBeforeSalmon() : void
{
var x:Object = productData.category[0].product[0];
var y:Object = newFish;
productData = productData.insertChildBefore(x, y);
myTree.dataProvider = productData;
}
]]>
</mx:Script>
<mx:Tree id="myTree" width="300" height="200" labelField="@name"
showRoot="false" dataProvider="{productData}" />
<mx:Button label="Append to End" click="appendToEnd()" y="210"/>
<mx:Button label="Insert after Fish" click="insertAfterFish()"
y="235"/>
<mx:Button label="Insert before Salmon"
click="insertBeforeSalmon()" y="260"/>
</mx:Application>
--
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
--
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
- Visit your group "flexcoders" on the web.
- To unsubscribe from this group, send an email to:
[EMAIL PROTECTED]
- Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.

