4
我有一个奇怪的情况,我不明白为什么,我已经实现了IEventDispatcher接口没有编制,我越来越Error: Call to a possibly undefined method addEventListener
和Error: Call to a possibly undefined method removeEventListener.
为什么我为实现的IEventDispatcher接口获取“未定义的方法”?
有一个很好的机会,我做的事情令人难以置信的愚蠢在这里,我只是不知道它是什么...
以下是那些在setTransformListner的身体和“removeTransformListener”抛出这些错误(意为“查看”工作方法的类中的方法:
public function setTransformListener(view:AbstractView):void
{
view.addEventListener(CustomEvent.TRANSFORM, transform);
}
public function removeTransformListener(view:AbstractView):void
{
view.removeEventListener(CustomEvent.TRANSFORM, transform);
}
private function transform(e:CustomEvent):void
{
}
这里是事件D ispatcher类...
package view
{
import flash.events.Event;
import flash.events.EventDispatcher;
import flash.events.IEventDispatcher;
public class AbstractView implements IEventDispatcher
{
private var _dispatcher:EventDispatcher;
public function AbstractView():void
{
_dispatcher = new EventDispatcher(this);
}
/* INTERFACE flash.events.IEventDispatcher */
public function addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
{
_dispatcher.addEventListener(type, listener, useCapture, priority, useWeakReference);
}
public function dispatchEvent(evt:Event):Boolean
{
return _dispatcher.dispatchEvent(evt);
}
public function hasEventListener(type:String):Boolean
{
return _dispatcher.hasEventListener(type);
}
public function removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void
{
_dispatcher.removeEventListener(type, listener, useCapture);
}
public function willTrigger(type:String):Boolean
{
return _dispatcher.willTrigger(type);
}
}
}
感谢Baris,“view”参数确实与包名“view”冲突。通过将“view”参数更改为“abstractView”,它解决了问题。我以前更改过类名,但并不认为“本地”参数名称会导致冲突。我错了,完全错过了!来自美国的感恩节快乐:) – antman
很高兴解决了!感恩节快乐! –