Hello,
I’ve got a weird scenario, where I register 5 event listeners for particular event, and only 3 of them are fired.
I’ve tried to reproduce this issue in a sample project, but as usual, this is not trivial.
Anyway, I was hoping someone could help me understand how Runtime event dispatch works. I’ve tried to simulate it and created my own dispatcher, and using it - it works just fine.
Anyway…
The function listening for the event, will remove itself as a listener (inside there’s the Runtime:removeEventListener call), so it’s easy to spot how many of them are not called.
Here’s how the Runtime._functionListeners.myEvent look like before the dispatch:
2014-03-03 11:54:10.868 Corona Simulator[5178:507] SHALLOW PRINTING TABLE table: 0x7fe27b5d93e0 [@level:167] 2014-03-03 11:54:10.868 Corona Simulator[5178:507] 1 : function: 0x7fe27b5d9300 2014-03-03 11:54:10.868 Corona Simulator[5178:507] 2 : function: 0x7fe283572f80 2014-03-03 11:54:10.868 Corona Simulator[5178:507] 3 : function: 0x7fe281eb80c0 2014-03-03 11:54:10.868 Corona Simulator[5178:507] 4 : function: 0x7fe28538a790 2014-03-03 11:54:10.868 Corona Simulator[5178:507] 5 : function: 0x7fe2851819b0 2014-03-03 11:54:10.868 Corona Simulator[5178:507] SHALLOW FINISHED PRINTING TABLE
Here’s the object with the function to be called “in it”: [not the address of the removeMe function]
2014-03-03 11:54:10.866 Corona Simulator[5178:507] -------------- 53806.838 -------------- 2014-03-03 11:54:10.866 Corona Simulator[5178:507] SHALLOW PRINTING TABLE table: 0x7fe283571f90 [@level:166] 2014-03-03 11:54:10.866 Corona Simulator[5178:507] show : function: 0x7fe2835283d0 2014-03-03 11:54:10.866 Corona Simulator[5178:507] \_proxy : userdata: 0x7fe283571f88 2014-03-03 11:54:10.866 Corona Simulator[5178:507] removeSelf : function: 0x7fe283572580 2014-03-03 11:54:10.867 Corona Simulator[5178:507] removeMe : function: 0x7fe283572f80 2014-03-03 11:54:10.867 Corona Simulator[5178:507] \_class { 2014-03-03 11:54:10.867 Corona Simulator[5178:507] removeEventListener : function: 0x7fe285394630 2014-03-03 11:54:10.867 Corona Simulator[5178:507] addEventListener : function: 0x7fe2853945d0 2014-03-03 11:54:10.867 Corona Simulator[5178:507] \_\_index { 2014-03-03 11:54:10.867 Corona Simulator[5178:507] } 2014-03-03 11:54:10.867 Corona Simulator[5178:507] } 2014-03-03 11:54:10.867 Corona Simulator[5178:507] hide : function: 0x7fe283528440 2014-03-03 11:54:10.867 Corona Simulator[5178:507] SHALLOW FINISHED PRINTING TABLE 2014-03-03 11:54:10.867 Corona Simulator[5178:507] --------------
and here’s the Runtime._functionListeners.myEvent after the dispatch:
2014-03-03 11:54:10.949 Corona Simulator[5178:507] -------------- 53890.056 -------------- 2014-03-03 11:54:10.949 Corona Simulator[5178:507] SHALLOW PRINTING TABLE table: 0x7fe27b5d93e0 [@level:169] 2014-03-03 11:54:10.949 Corona Simulator[5178:507] 1 : function: 0x7fe283572f80 2014-03-03 11:54:10.950 Corona Simulator[5178:507] 2 : function: 0x7fe28538a790 2014-03-03 11:54:10.950 Corona Simulator[5178:507] SHALLOW FINISHED PRINTING TABLE 2014-03-03 11:54:10.950 Corona Simulator[5178:507] --------------
Inside every function listening for “myEvent” event, I’ve got a print as the first line, so I can determine which one was called and which was not. They were not
I’m just wondering, how is this possible?
Krystian