我基本上有一个班级:
public class WindowEvent extends Event
{
public static const WARNEVENT:String = "warnEvent";
public static const TASKREQEVENT:String = "taskRequestEvent";
public static const TASKANNOUNCE:String = "taskAnnounce";
public static const WINDOWCHANGE:String = "windowChange";
public static const ILLEGALPOSITION:String = "illegalPosition";
// insert brevity
}
前四个事件工作正常,但我刚添加了ILLEGALPOSITION
并尝试了这个:
// inside Window.as
private function checkDimensions():void {
if(!Window._legalBoundaryEnable)
return;
... var pass:Boolean = Window.legalBoundary.containsRect(
455 this.getBounds(stage));
456 if(!pass) {
457 this.dispatchEvent(new WindowEvent(WindowEvent.ILLEGALPOSITION,
... "Illegal Position etc."));
}
}
当我点击调度方法时,Flex向我发出了这个堆栈:
TypeError: Error #1034: Type Coercion failed: cannot convert ¬ flex.utils.ui::WindowEvent@511dce41 to flash.events.MouseEvent. at flash.events::EventDispatcher/dispatchEventFunction() at flash.events::EventDispatcher/dispatchEvent() at mx.core::UIComponent/dispatchEvent() ¬ [C:\autobuild\~\UIComponent.as:9298] at flex.utils.ui::Window/checkDimensions()[C:\Users\~\Window.as:457] at flex.utils.ui::Window/stageResized()[C:\Users\~\Window.as:220]
从跟踪中可以看出,Window.as:457
是最后一个用户代码行。所以WTF flash.events.EventDispatcher.dispatchEventFunction
尝试使用MouseEvent
?
答案 0 :(得分:5)
通常会发生该错误,因为您设置的侦听器具有不正确的事件参数类型。我很确定这一定是这种情况。
检查您为该事件设置的所有侦听器,并确保该功能
someFunction(event : WindowEvent) : void
答案 1 :(得分:3)
尝试使用ILLEGALPOSITION
的其他值,可能会由Flex本身(或代码的其他部分)使用"illegalPosition"
并与鼠标事件相关。因此,当该事件处理程序触发时,它会尝试将您的事件转换为MouseEvent
,因为它认为它应该是一个。