Flex树itemclick事件不起作用
我正在创建一个可重用的弹性树组件。我想坚持使用 itemclick 功能。这样,当用户单击树的分支之一上的任意位置时。分支机构扩大。 我的问题是我不知道如何启动侦听器功能。 我想做的是完全在 as3 中创建树。 (没有 mxml)。 通常我在 mxml 中的树上设置 itemClick。但我想在as3中做到这一点。 我的组件中有更多功能,但我已删除它们,以便更容易阅读。
谁能帮我解决这个问题吗?我想如果我重写 createChilderen 函数并在其中添加事件监听器,它就会起作用。但没有运气。
这是我的代码;
package
{
import mx.controls.Tree;
import mx.controls.listClasses.IListItemRenderer;
import mx.events.ItemClickEvent;
import mx.events.ListEvent;
public class MyTree extends Tree
{
public function MyTree()
{
super();
}
private function tree_itemClick(evt:ListEvent):void {
var item:Object = Tree(evt.currentTarget).selectedItem;
if (dataDescriptor.isBranch(item)) {
expandItem(item, !isItemOpen(item), true);
}
}
override protected function createChildren():void{
super.createChildren();
addEventListener(ListEvent.ITEM_CLICK, tree_itemClick, true);
}
}
}
I'm creating a reusable flex tree component. And i would like to stick in the itemclick function. So that when a user clicks anywhere on one of the tree's Branches. the branch expands.
My problem is that I don't know how I can get the listener function to fire.
What I would like to do is create the tree completely in as3. (no mxml).
Normally I set the itemClick on tree in the mxml. but I want to do this in as3.
My component has a lot more functions in it but I have deleted them so that it becomes easier to read.
Can anyone help me out on this one? I Thought if I override the createChilderen function and add the eventlistener in there, that it would work. But no luck.
this is my code;
package
{
import mx.controls.Tree;
import mx.controls.listClasses.IListItemRenderer;
import mx.events.ItemClickEvent;
import mx.events.ListEvent;
public class MyTree extends Tree
{
public function MyTree()
{
super();
}
private function tree_itemClick(evt:ListEvent):void {
var item:Object = Tree(evt.currentTarget).selectedItem;
if (dataDescriptor.isBranch(item)) {
expandItem(item, !isItemOpen(item), true);
}
}
override protected function createChildren():void{
super.createChildren();
addEventListener(ListEvent.ITEM_CLICK, tree_itemClick, true);
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)