[Resolved] Runtime eventListener with parameters

Hi!

How can I :

  1. pass parameters to a function I call with a Runtime eventListener
  2. remove the Runtime eventListener (in that function on a condition)
  3. return parameters from the function.

I found at that

function myFunction(parameter)  
return function()  
 print( "Listener called with paramater: " ..paramater)  
 end  
end  
  
paramater = "hello"  
Runtime:addEventListener( "enterFrame", myFunction(parameter))  

seems to work, but I have no clue how to remove the eventlistener and how to return parameters (or should I use global variables for that?) .

If I put Runtime:removeEventListener( "enterFrame", myFunction(parameter)) in the function I get a stack overflow error.

Runtime:removeEventListener( "enterFrame", myFunction) is just ignored.

thx! [import]uid: 148841 topic_id: 30939 reply_id: 330939[/import]

Similar to with a timer you’d pass these in a specific way, see this thread, it’s pretty thorough; http://developer.coronalabs.com/forum/2010/08/05/how-pass-additional-arguments-parameters-event-listener

Peach :slight_smile: [import]uid: 52491 topic_id: 30939 reply_id: 123733[/import]

Yea thx but the thread does not say how to remove the runtime eventlistener like above.

[Edit] Ah ok I figured it out, I store the function call in a variable :slight_smile:

bla = myFunction(paramater) 

then I can add and remove

Runtime:removeEventListener( "enterFrame", bla) 

Similar to with a timer you’d pass these in a specific way, see this thread, it’s pretty thorough; http://developer.coronalabs.com/forum/2010/08/05/how-pass-additional-arguments-parameters-event-listener

Peach :slight_smile: [import]uid: 52491 topic_id: 30939 reply_id: 123733[/import]

Yea thx but the thread does not say how to remove the runtime eventlistener like above.

[Edit] Ah ok I figured it out, I store the function call in a variable :slight_smile:

bla = myFunction(paramater) 

then I can add and remove

Runtime:removeEventListener( "enterFrame", bla)