Custom TreeItemRenderer removes custom component
Hello,
I have created custom TreeItemRenderer in which i am trying to draw colored Hbox bar at each node except root. Intially when i click on root node it opens first child node with bar but when i open leaf node it does not showing bar and removing existing bard from other few child nodes. Its calling itemrenderer on mouseonver eventhough i have disabled. I am attaching code would please any one help me to resolve this issue.
Attaching Code here
package Adodbe.renderers
{
import flash.display.DisplayObject;
import flash.events.Event;
import flash.events.MouseEvent;
import mx.collections.*;
import mx.containers.HBox;
import mx.controls.Label;
import mx.controls.TextInput;
import mx.controls.treeClasses.*;
import mx.core.UITextField;
public class PercentCorrectTreeRenderer extends TreeItemRenderer
{
private var hBox:HBox;
private var barHBox:HBox;
private var itemLabel:Label;
private var textBar:Label;
private var fillBar:TextInput;
// Define the constructor.
public function PercentCorrectTreeRenderer()
{
super();
}
override public function set data(value:Object):void
{
super.data = value;
var treeItem:Object = TreeListData(super.listData).item;
if(!treeItem) return;
if(treeItem.Element && treeItem.Element == "Root")
{
this.setStyle("styleName", "percentCorrectTreeSection");
}
else
{
this.setStyle("styleName", "percentCorrectTreeSectionItem");
}
}
override protected function createChildren():void
{
super.createChildren();
label.addEventListener(MouseEvent.CLICK, onLabelClick);
label.addEventListener(MouseEvent.MOUSE_OVER, onLabelMouseOver);
barHBox = new HBox();
fillBar = new TextInput();
textBar = new Label();
fillBar.editable = false;
fillBar.styleName = "barStrengths";
barHBox.addChild(fillBar);
barHBox.addChild(textBar);
barHBox.setStyle("paddingLeft",200)
this.addChild(barHBox);
}
override protected function measure():void
{
super.measure();
var w:Number = data ? ( listData as TreeListData ).indent : 0;
if ( disclosureIcon )
w += disclosureIcon.width;
if ( icon )
w += icon.measuredWidth;
if ( label.width < 4 || label.height < 4 )
{
label.width = 4;
label.height = 16;
}
if ( isNaN( explicitWidth ) )
{
w += label.getExplicitOrMeasuredWidth( );
w += barHBox.getExplicitOrMeasuredWidth( );
measuredWidth = w;
measuredHeight = Math.max( barHBox.getExplicitOrMeasuredHeight( ), label.getExplicitOrMeasuredHeight( ) );
}
else
{
label.width = Math.max(explicitWidth - ( w + barHBox.getExplicitOrMeasuredWidth( ) ), 4 );
measuredHeight = Math.max( barHBox.getExplicitOrMeasuredHeight( ), label.getExplicitOrMeasuredHeight( ) );
if ( icon && icon.measuredHeight > measuredHeight )
measuredHeight = icon.measuredHeight;
}
}
override protected function commitProperties( ): void
{
super.commitProperties( );
}
override protected function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void
{
super.updateDisplayList(unscaledWidth, unscaledHeight);
barHBox.setActualSize(barHBox.getExplicitOrMeasure dWidth(),barHBox.getExplicitOrMeasuredHeight());
if (icon)
icon.y = (unscaledHeight - icon.height) / 2;
if (disclosureIcon)
disclosureIcon.y = (unscaledHeight - disclosureIcon.height) / 2;
var treeItem:Object = TreeListData(super.listData).item;
if(!treeItem) return;
if(treeItem.Element && treeItem.Element == "Root")
{
this.label.text = treeItem.Title +" - "+treeItem.NumberCorrect +" correct ("+treeItem.PercentCorrect+"%)";
barHBox.visible = false;
fillBar.setStyle("borderStyle","none");
}
else
{
if(treeItem.children.length > 0)
{
this.label.text = treeItem.Title +" "+treeItem.NumberCorrect;
fillBar.width = Math.round((200 * Number(treeItem.PercentCorrect))/100);
fillBar.height = 15;
textBar.text = treeItem.PercentCorrect + "%";
fillBar.styleName = "barStrengths";
barHBox.y = disclosureIcon.y - 5
}
else if(treeItem.children.length == 0)
{
disclosureIcon.visible = false;
this.label.text = treeItem.Title +" "+treeItem.NumberCorrect;
fillBar.width = Math.round((200 * Number(treeItem.PercentCorrect))/100);
fillBar.height = 15;
textBar.text = treeItem.PercentCorrect + "%";
fillBar.styleName = "barStrengths";
barHBox.y = disclosureIcon.y - 5
}
}
}
private function onLabelClick(event:Event):void
{
var obj:Object = event.target;
}
private function onLabelMouseOver(event:Event):void
{
var obj:Object = event.target;
}
}
}
Any help would much appriciated.
Thanks
|