Используя Flex 4.1, я пытаюсь создать элемент Tree с пользовательским ItemRenderer (MXTreeItemRenderer). моя проблема в том, что всякий раз, когда я складываю и разворачиваю корневой элемент, порядок элементов меняется ... это странно, может быть, XML не отформатирован должным образом.
есть идеи?
мой файл Main.mxml:
<?xml version="1.0" encoding="utf-8"?>
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx" minWidth="955" minHeight="600">
<!-- Launch your application by right clicking within this class and select Debug As > FDT SWF Application -->
<fx:Declarations>
<fx:XML id="moshe">
<notifications>
<root label="a" state="root_item">
<node state="item" label="moshe"/>
<node state="item" label="moshe"/>
</root>
<root label="b" state="root_item"/>
<root label="c" state="root_item"/>
<root label="d" state="root_item"/>
<root label="e" state="root_item"/>
</notifications>
</fx:XML>
</fx:Declarations>
<mx:Tree dataProvider="{moshe}" width="500" itemRenderer="TheRenderer" labelField="@label" showRoot="false" folderClosedIcon="{null}" defaultLeafIcon="{null}"
folderOpenIcon="{null}" />
</s:Application>
и мой Рендерер предметов:
<?xml version="1.0" encoding="utf-8"?>
<s:MXTreeItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
<s:states>
<s:State name="normal" basedOn="{data.@state}"/>
<s:State name="hovered" basedOn="{data.@state}"/>
<s:State name="selected" basedOn="{data.@state}"/>
<s:State name="root_item"/>
<s:State name="item" />
</s:states>
<fx:Script>
<![CDATA[
import com.flexer.Debug;
import mx.controls.Alert;
override public function set data(value:Object):void {
super.data = value;
if(treeListData.hasChildren)
{
setStyle("color", 0xff0000);
setStyle("fontWeight", 'bold');
}
else
{
setStyle("color", 0x000000);
setStyle("fontWeight", 'normal');
}
}
// Override the updateDisplayList() method
// to set the text for each tree node.
override protected function updateDisplayList(unscaledWidth:Number,
unscaledHeight:Number):void {
super.updateDisplayList(unscaledWidth, unscaledHeight);
if(super.data)
{
if(treeListData.hasChildren)
{
var tmp:XMLList =
new XMLList(treeListData.item);
var myStr:int = tmp[0].children().length();
this.labelField.text= super.data.@label + " (" + myStr.toString() + ")";
}
}
}
]]>
</fx:Script>
<s:HGroup left="0" right="0" top="0" bottom="0" verticalAlign="middle" includeIn="root_item">
<s:Rect id="indentationSpacer" width="{treeListData.indent}" percentHeight="100" alpha="0">
<s:fill>
<s:SolidColor color="0xFFFFFF" />
</s:fill>
</s:Rect>
<s:Group id="disclosureGroup">
<s:BitmapImage source="{treeListData.disclosureIcon}" visible="{treeListData.hasChildren}" />
</s:Group>
<s:BitmapImage source="{treeListData.icon}" />
<s:Label id="labelField" text="{treeListData.label}" paddingTop="2"/>
</s:HGroup>
<s:HGroup includeIn="item">
<s:Label text="{treeListData.label}"/>
</s:HGroup>
</s:MXTreeItemRenderer>