我收到以下错误
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]
EmergencyEvent.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);
}
我仍然遇到同样的错误。
解决了,我在添加事件监听器时使用了错误的函数,复制粘贴错误。
答案 0 :(得分:2)
问题在于您的侦听器功能。参数类型必须为EmergencyEvent
而不是EmergencyItem
。