-1

我有带有方法的 EventManager 类:

public function addEvent(obj:IEventDispatcher, event:String, listener:Function, 
       useCapture:Boolean = false, priority:int = 0, 
       useWeakReference:Boolean = false):void 
{           
   obj.addEventListener(event, listener, useCapture, priority, useWeakReference);
   [here event is pushed in my stack]    
}

我想做这个:

public class CustomClass extends Sprite
{    
    public override function addEventListener(type:String, listener:Function, 
           useCapture:Boolean = false, priority:int = 0, 
           useWeakReference:Boolean = false):void
    {
        eventManager.addEvent(this, type, listener, useCapture, priority, useWeakReference);            
    }    
}

但结果调用堆栈是:

   customClass.addEventListener ->

   eventManager.addEvent ->

   customClass.addEventListener ->

   eventManager.addEvent ->

   customClass.addEventListener ->

   ...

等等......因为我在 eventManager.addEvent 中调用了 obj.addEventListener

也许你能给我一个解决这个问题的方法吗?

4

1 回答 1

0

您创建了一个递归循环,因为您在事件管理器中调用了调用事件管理器等的对象上的 addEventlistener 函数......您可能的意思是只存储对对象的引用和事件管理器中的参数,而不是实际调用addEventlistener-function 从那里。

于 2012-12-13T22:23:34.133 回答