动作脚本 3 事件管理器



我有带有方法的类事件管理器:

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

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

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

相关内容

  • 没有找到相关文章

最新更新