Flex 类和 itemRenderer 的意外行为
我陷入了一种我没有预料到的行为,请解释我以理解并解决它。 - 问题如下:我有一个包含标签的类,该类在 itemRenderer 内部使用,整个过程没有异常,但它不显示标签的文本。 我尝试过添加按钮,但问题仍然存在 - 它实际上从未添加按钮。
为什么?
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";
}
}
... itemRenderer 内部:
<sl:BusTreeNode width="100%" />
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%" />
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我想问题是您的
BusTreeNode
类中没有measure()
实现。所以你的组件默认大小为 0x0。这个声明:仍然给0作为高度。
您可以阅读有关 Flex 组件测量的更多信息 这里。 本文对于创建自定义组件非常有用。
I suppose the problem is you haven't
measure()
implementation in yourBusTreeNode
class. So your component has 0x0 size by default. This declaration:still give 0 as height.
You can read more about Flex components measuring here. And this article is very useful for creating custom components.
从 Spark(或 Flex 3 中的 mx)ItemRenderer 类扩展更容易。创建一个新的 MXML 文件,如下所示:
“labelDisplay”的“text”属性将自动由其使用的 List(或其他数据组件)设置。
此外,在 Flex 组件生命周期中,应将可视元素添加到 displayList在 createChildren() 方法中。因此,如果你绝对想用纯 ActionScript 编写它,你可以这样做,但它更难:
It's easier to extend from the spark (or mx in Flex 3) ItemRenderer class. Create a new MXML file like this:
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: