5

我基本上有一堂课:

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:错误 #1034:类型强制失败:无法转换 ¬
        flex.utils.ui::WindowEvent@511dce41 到 flash.events.MouseEvent。
    在 flash.events::EventDispatcher/dispatchEventFunction()
    在 flash.events::EventDispatcher/dispatchEvent()
    在 mx.core::UIComponent/dispatchEvent() ¬
        [C:\autobuild\~\UIComponent.as:9298]
    在 flex.utils.ui::Window/checkDimensions()[C:\Users\~\Window.as:457]
    在 flex.utils.ui::Window/stageResized()[C:\Users\~\Window.as:220]

从跟踪中可以看出,是最后一个用户代码行。所以 WTF试图用?Window.as:457flash.events.EventDispatcher.dispatchEventFunctionMouseEvent

4

2 回答 2

5

该错误通常发生是因为您设置的侦听器具有不正确的事件参数类型。我很确定这里一定是这种情况。

检查您为该事件设置的所有侦听器并确保该函数是

someFunction(event : WindowEvent) : void
于 2009-04-25T20:46:48.403 回答
3

尝试使用另一个值ILLEGALPOSITION"illegalPosition"可能会被 Flex 本身(或代码的另一部分)使用并与鼠标事件相关。因此,当该事件处理程序触发时,它会尝试将您的事件转换为 a MouseEvent,因为它认为它应该是一个。

于 2009-04-25T20:11:59.407 回答