我将自定义事件currentTarget转换为组件时遇到问题。当我试图从其父容器中删除元素时,我得到错误。这是什么交易?
TypeError: Error #1034: Type Coercion failed: cannot convert mx.events::FlexEvent@8811c41 to com.modultek.pis.itemmachine.search.events.SortEvent.
private function sortSelection_removeHandler(event:SortEvent):void
{
var sortSelection:SortSelection = event.currentTarget as SortSelection;
this.removeElement(sortSelection);
}
组件将被删除但我收到此错误。
答案 0 :(得分:2)
您的问题根本不在var sortSelection:SortSelection = event.currentTarget as SortSelection;
行。
仔细阅读错误消息。它告诉您,从FlexEvent
到SortEvent
的投射无效,该投射发生在
private function sortSelection_removeHandler(event:SortEvent):void
将功能签名中的event:SortEvent
更改为event:FlexEvent
或event:Event
答案 1 :(得分:0)
问题是我的调度课上没有事件声明。
[Event(name="remove" , type=".....search.events.SortEvent")]