Passing data from widget.newButton, to function

I posted on StackOverflow yesterday, this is the copy-paste of that question;
Thanks in advance!

I have scoured the documentation and google for a solution but none was found.

Simply: I want to pass data to a function, when a button is pressed. Issue: The buttons are dynamically created, so the data must be presented when the button is built.

The code looks like this;

 myButton = widget.newButton({ x = width \* 0.875, y = height \* heightChange, width = width \* 0.18, height = height \* 0.09, defaultFile = "Assets/Images/button\_up.png", overFile = "Assets/Images/button\_down.png", onEvent = func\_myFunction })

But I want to do something like;

 onEvent = func\_myFunction("My Data")

or

 onEvent = func\_myFunction, myData

neither of which work. Any ideas?

You can’t pass data like that. What you can do is use an anonymous function:

onEvent = function() func\_myFunction("My Data"); end

Rob

But what if in this function I want change button label? Normally I use event.target:setLabel() but in this case there is no event in function. How to send button and params together?

onEvent = function( event ) func\_myFunction( event, "My Data"); end

You can’t pass data like that. What you can do is use an anonymous function:

onEvent = function() func\_myFunction("My Data"); end

Rob

But what if in this function I want change button label? Normally I use event.target:setLabel() but in this case there is no event in function. How to send button and params together?

onEvent = function( event ) func\_myFunction( event, "My Data"); end