加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

Flex Type Coercion,我认为这是精神上的

发布时间:2020-12-15 01:48:07 所属栏目:百科 来源:网络整理
导读:我基本上有一节课: public class WindowEvent extends Event{ public static const WARNEVENT:String = "warnEvent"; public static const TASKREQEVENT:String = "taskRequestEvent"; public static const TASKANNOUNCE:String = "taskAnnounce"; public s
我基本上有一节课:

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吗?

解决方法

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

检查您为该事件设置的所有侦听器,并确保该功能

someFunction(event : WindowEvent) : void

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读