apache-flex - Flex Type Coercion,我认为它已经失去了精神

标签 apache-flex flash actionscript-3 mxml

我基本上有一个类:

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."));
       }
    }

所以当我点击 dispatch 方法时,Flex 向我吐出这个堆栈:

类型错误:错误 #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]

从跟踪中可以看出,Window.as:457 是最后一行用户代码。那么 WTF 是 flash.events.EventDispatcher.dispatchEventFunction 试图使用 MouseEvent 吗?

最佳答案

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

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

someFunction(event : WindowEvent) : void

关于apache-flex - Flex Type Coercion,我认为它已经失去了精神,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/789627/

相关文章:

javascript - 从 flash 调用 jQuery 函数

c# - 通过 SOCKET 发送文件

mysql - 我无法从 Flex 将 html 富文本添加到 mySQL 数据库

apache-flex - 从 zip 存档中提取 zip 文件,而不将整个文件加载到内存中

javascript - 将 flash 添加到 html 页面以与 Jquery 一起使用的最简单方法是什么?

Flash AS2 (CS4) - setInterval 导致 for 循环不起作用

flash - 使用哪种语言来创建网络机器人?

actionscript-3 - 如何加载 swf 并与之交互?

apache-flex - Flex 自定义组件不接受 : Multiple initializer values for default property, 'text' 类型的 'String' 脚本

actionscript-3 - Flex - 在后台运行空气应用程序