Race condition firing events in AS3
Posted
by crispclean
on Stack Overflow
See other posts from Stack Overflow
or by crispclean
Published on 2009-12-02T17:30:56Z
Indexed on
2010/05/14
5:04 UTC
Read the original article
Hit count: 307
Hello
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);
}
© Stack Overflow or respective owner