在AS3竞争条件触发事件条件、竞争、事件

2023-09-08 13:57:57 作者:存在的不明显

我有一些麻烦射击和消除在正确的编年史顺序事件。下面的code给出了下面的输出:

在保存的海报到数据库,并调度事件 呼叫服务,调度事件删除= FALSE 呼叫服务,调度事件删除= FALSE 呼叫服务,调度事件删除= TRUE 在保存的海报到数据库,并调度事件 在保存的海报到数据库,并调度事件 当然,

这应该是更多的是这样的:

在保存的海报到数据库,并调度事件 呼叫服务,调度事件删除= TRUE 在保存的海报到数据库,并调度事件 呼叫服务,调度事件删除= TRUE 在保存的海报到数据库,并调度事件 呼叫服务,调度事件删除= TRUE

有人可以帮助我?我跑出来就想法如何解决这个问题。

THX!

 的(VAR我:= 0;我3;;我++){
        createPoster();
    }

    功能createPoster(){
        Main.db.savePoster();
        Main.db.addEventListener(Config.evt_SAVEPOSTER_READY,callService);
    }

    功能callService(){
       Main.db.removeEventListener(Config.evt_SAVEPOSTER_READY,callService);
    }
 

解决方案

现在的问题是,你正在注册相同的功能 callService 对于同一事件配置.evt_SAVEPOSTER_READY EvenDispatcher 对象分贝。因此,一旦第一savePoster分派成功保存海报后,分贝接收事件和三个事件处理器(在此情况下callService)称为因为callService被登记三次该事件。所以,一个解决办法是从海报调度事件

 的(VAR我:= 0;我3;;我++){
  createPoster();
}
功能createPoster(){
  海报= Main.db.savePoster();
  poster.addEventListener(Config.evt_SAVEPOSTER_READY,callService);
}
功能callService(E:PosterEvent){
  e.target.removeEventListener(Config.evt_SAVEPOSTER_READY,callService);
}  

号称 Redis Plus,来看看 KeyDB 性能有多炸裂

I have some troubles firing and removing events in the right chronicle order. The code below gives the following output:

save poster into db, and dispatch event calling service, dispatch event removed = false calling service, dispatch event removed = false calling service, dispatch event removed = true save poster into db, and dispatch event save poster into db, and dispatch event

of course this should be more something like:

save poster into db, and dispatch event calling service, dispatch event removed = true save poster into db, and dispatch event calling service, dispatch event removed = true save poster into db, and dispatch event calling service, dispatch event removed = true

Can someone help me with this? I'm running out of ideas on how to tackle this.

thx!

    for(var i:int = 0;i< 3;i++){
        createPoster(); 		
    }

    function createPoster(){
        Main.db.savePoster();
        Main.db.addEventListener(Config.evt_SAVEPOSTER_READY, callService);
    }

    function callService(){
       Main.db.removeEventListener(Config.evt_SAVEPOSTER_READY, callService);
    }

解决方案

The problem is that you are registering same function callService for same event Config.evt_SAVEPOSTER_READY on single EvenDispatcher objectdb. So as soon first savePoster dispatches the event after successfully saving the poster, db receives the event and three eventHandlers (in this case callService) are called because callService is registered thrice. So one solution would be dispatching the events from Poster.

for(var i:int = 0;i< 3;i++){
  createPoster();
}
function createPoster(){
  poster = Main.db.savePoster();
  poster.addEventListener(Config.evt_SAVEPOSTER_READY, callService);
}
function callService(e:PosterEvent){
  e.target.removeEventListener(Config.evt_SAVEPOSTER_READY, callService);
}

 
精彩推荐
图片推荐