If an event listener calls another event listener...

If an event completion listener calls a 2nd event completion listener how is the return execution?

-- EVENT COMPLETION LISTENER 2  
function onTransitionComplete(event)  
 -- do stuff 3  
end  
  
-- EVENT COMPLETION LISTENER 1  
function onEventSoundComplete(event)  
 -- do stuff 2  
 transition.to(aGrp, {time=500, x=0, onComplete=onTransitionComplete}) -- Transition a display group with a event completion listener  
end  
  
-- MAIN CODE  
media.playEventSound("aSound.caf", onEventSoundComplete) -- Play a sound with a event completion listener  
-- do stuff 1  

I know that the code after media.playEventSound will execute immediately before aSound.caf has finished playing.

onEventSoundComplete is the event completion listener for aSound.caf and it sets up onTransitionComplete as an event completion listener for the aGrp transition.

Will onEventSoundComplete return (or finish executing) before onTransitionComplete completes? Or will it create within the Corona runtime a stack like happens in non-event-based code where if a 1st function calls a 2nd function, which call a 3rd function, and each inner function must return to be popped off the stack?
[import]uid: 295 topic_id: 1550 reply_id: 301550[/import]

Not sure exactly what you’re asking but:

sound is played, at end of sound, onEventSoundComplete called, transition.to called with onComplete listener specified, after transition completes, onTransitionComplete called…

Does this answer your question? Event listeners don’t exist anywhere until the code that adds them is executed… [import]uid: 6678 topic_id: 1550 reply_id: 4373[/import]

I know the calling sequence. That’s no problem. I want to know how event listeners end. Since one is called from within another I’m worried about when the event listener functions return. Does the second one HAVE to end before the first one CAN end?

Or CAN the 1st one end BEFORE the 2nd one end in spite of the 1st one having called the 2nd one?
[import]uid: 295 topic_id: 1550 reply_id: 4375[/import]

I’m still not understanding.

onTransitionComplete can only be called after the sound completes since it isn’t a live listener until the sound completes because onEventSoundComplete wouldn’t have been called yet… [import]uid: 6678 topic_id: 1550 reply_id: 4376[/import]

Yeah that’s right.

But because onTransitionComplete (the 2nd listener to be called) is called by onEventSoundComplete (the 1st listener to be called), Does onTransitionComplete have to return (finish its execution) before onTransitionComplete can finish its execution? [import]uid: 295 topic_id: 1550 reply_id: 4377[/import]

Actually: onTransitionComplete is not being called by onEventSoundComplete.

Those functions are all asynchronously. So they do not wait on each other to finish.

It is called by the framework!

You do not “call” an event handler ever. You setup what gets called when the event gets dispatched.

Event calling may get delayed if your code is still running when an even condition happens. But that should be no problem for your case. [import]uid: 6928 topic_id: 1550 reply_id: 4378[/import]