0

我收到以下错误

TypeError: Error #1034: Type Coercion failed: cannot convert EmergencyItems::EmergencyEvent@c607bb1 to EmergencyItems.EmergencyItem.
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at EmergencyItems::EmergencyItem/request()[\EmergencyItems\EmergencyItem.as:64]

紧急事件.as

public class EmergencyEvent extends Event {

    public static const EVENT_REQUEST:String = "requestingr";


    public var item:EmergencyItem;

    public function EmergencyEvent(type:String, item:EmergencyItem, bubbles:Boolean=false, cancelable:Boolean=false) {
        super(type, bubbles, cancelable);
        this.item = item;
    }

    override public function clone():Event {
        return new EmergencyEvent(type, item);
    }
}

EmergencyItem.as(第 64 行以“dispatchEvent...”开头)

public class EmergencyItem extends EventDispatcher {      

    public function request():void {
        dispatchEvent(new EmergencyEvent(EmergencyEvent.EVENT_REQUEST, this));
    }
}

我已经环顾了很长时间,但找不到问题(或解决方案)。我认为可能是“this”以某种方式引用了 EmergencyEvent 而不是 EmergencyItem,所以我修改了 EmergencyItem.as

public function request():void {
        var self:EmergencyItem = this;
        var eEvent:EmergencyEvent = new EmergencyEvent(EmergencyEvent.EVENT_REQUEST, self);
        dispatchEvent(eEvent);
    }

我仍然遇到同样的错误。

已解决,我在添加事件监听器时使用了错误的函数,复制粘贴错误。

4

1 回答 1

2

问题出在您的侦听器功能上。参数类型必须是 ofEmergencyEvent和 not EmergencyItem

于 2013-06-10T20:47:53.637 回答