Apache flex FLEX,Actionscript:如何调用CustomEvent?
我在Flex中创建了一个自定义MouseeEvent:Apache flex FLEX,Actionscript:如何调用CustomEvent?,apache-flex,actionscript-3,Apache Flex,Actionscript 3,我在Flex中创建了一个自定义MouseeEvent: package { import flash.events.MouseEvent; public class CustomMouseEvent extends MouseEvent { public var tags:Array = new Array(); public function CustomMouseEvent(type:String, tags:Array) {
package {
import flash.events.MouseEvent;
public class CustomMouseEvent extends MouseEvent {
public var tags:Array = new Array();
public function CustomMouseEvent(type:String, tags:Array) {
super(type, true);
this.tags = tags;
}
}
}
现在我想了解如何从Actionscript和MXML传递参数标记:
在actionscript中,我尝试了类似的方法,但不起作用:
newTag.addEventListener(MouseEvent.MOUSE_UP, dispatchEvent(new CustomMouseEvent(MouseEvent.MOUSE_UP,[newTag.name])));
在MXML中,我正在这样做,但效果不好:
<mx:LinkButton click="dispatchEvent(new CustomMouseEvent(MouseEvent.MOUSE_UP, bookmarksRepeater.currentItem.tags))" />
谢谢尝试将回调代码包装到函数中:
newTag.addEventListener(MouseEvent.MOUSE_UP, function(e:MouseEvent):void {
dispatchEvent(new CustomMouseEvent(MouseEvent.MOUSE_UP, [e.currentTarget.name]));
});
我认为MXML代码的问题在于,您正在使用中继器,并试图在重复完成后获取currentItem
。请尝试以下方法:
<mx:LinkButton click="dispatchEvent(new CustomMouseEvent(MouseEvent.MOUSE_UP, event.currentTarget.getRepeaterItem().tags))" />
这样,您只创建一个事件侦听器,而不是执行完全相同操作的
n
侦听器。此外,您可能会因为未重写克隆方法而收到TypeErrors。在你以后遇到它之前,你应该现在就把它修好
格里茨back2dos您是否尝试将类型更改为当前正在使用的类型以外的其他类型。类似CustomMouseEvent.MY_CUSTOM_MOUSE的东西,然后捕捉它,看看这是否有效。不确定使用与标准类型相同的类型名是否是一种好方法 嗯。。我对纽塔格也有同样的问题。newTag是在for循环中创建的,因此I newTag.name只是我添加的最后一个标记的名称(当我触发事件时,运行时)。那么解决方案是什么呢?刚刚更新了我的答案,显示使用事件的
currentTarget
来获得正确的newTag
对象。这样行吗?为什么要让你的类扩展MouseeEvent?我认为,如果您创建一个扩展事件的类,它会更容易、更清晰。(我猜如果您定义自己的事件名称并且在这种情况下不使用鼠标,您会做得更好)好的,我现在扩展事件
newTag.addEventListener(MouseEvent.MOUSE_UP, onTagClick);
...
protected function onTagClick(e:MouseEvent):void {
dispatchEvent(new CustomMouseEvent(MouseEvent.MOUSE_UP, [e.currentTarget.name]));
}