Reputation: 2604
I droped into a behaviour which i didnt expect, please explain me to understand and fix it. - The issue is as follow : I have a class which holds a label, and this class is used inside a itemRenderer as , the whole thing work withotu exception, but it doest not show the text of the label. I have tried with adding a Button but the issue remains - it never actually add an the button.
Why?
public class BusTreeNode extends UIComponent
{
protected var label : Label;
public function BusTreeNode()
{
super();
label = new Label();
this.addChild( label );
label.x = 40;
label.y = 2;
label.text = "test";
}
}
... Inside itemRenderer :
<sl:BusTreeNode width="100%" />
Upvotes: 0
Views: 281
Reputation: 11912
It's easier to extend from the spark (or mx in Flex 3) ItemRenderer class. Create a new MXML file like this:
<s:ItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark" >
<!-- label -->
<s:Label id="labelDisplay" />
</s:ItemRenderer>
The 'text' property of 'labelDisplay' will automatically be set by the List (or other data component) it's used in.
Furthermore, in the Flex component lifecycle, visual elements should be added to the displayList in the createChildren() method. So if you absolutely want to write it in pure ActionScript, you can do it like this, but it's harder:
public class MyItemRenderer extends ItemRenderer {
private var button:Button;
override protected function createChildren():void {
super.createChildren();
button = new Button();
addElement(button);
}
override public function set label(value:String):void {
super.label = button.label = value;
}
}
Upvotes: 1
Reputation: 14221
I suppose the problem is you haven't measure()
implementation in your BusTreeNode
class. So your component has 0x0 size by default. This declaration:
<sl:BusTreeNode width="100%" />
still give 0 as height.
You can read more about Flex components measuring here. And this article is very useful for creating custom components.
Upvotes: 2