4

I have a strange situation where I can't see why the IEventDispatcher interface that I have implemented is not compiling and I'm getting Error: Call to a possibly undefined method addEventListener and Error: Call to a possibly undefined method removeEventListener.

There's a good chance I'm doing something incredibly dumb here I just don't know what it is...

Here are the methods in the Class that are throwing these errors (meaning the methods working on "view" in the body of the setTransformListner and "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
{

}

Here is the Event Dispatcher Class...

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

    }

}

1 Answer 1

5

Wild guess, you package name is view and you are trying to call view.addEventListener, try changing the package name. Although the local var view should be used first.

1
  • 1
    Thanks Baris, it was indeed the case that the "view" parameter was conflicting with the package name "view." By changing the "view" parameter to "abstractView" it resolved the issue. I had changed the class name previously, but did not think that the "local" parameter name would cause a conflict. I was wrong and totally missed that! Happy Thanksgiving from the States :)
    – antman
    Nov 23, 2012 at 0:35

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.