How To Reference Widget In Listener Event Without Nil Error?

Hello,

 

I’m sure this is a dumb question but I am having trouble referencing the widget name in the listener event. I have the listener even first in the code. Then in the scene:createScene I have the code to create the widget. But when I try to check the status of checkbox widget in the listener event I get the error - attempt to index global ‘chkSaveEmail’ (a nil value). I assume this is because the widget is created after. How do I reference it though? I will want an event such as a Save button to see what all is checked, entered, etc.

 

Thanks,

 

Warren

 

Have you tried adding the local chkSaveEmail up top and then create chkSaveEmail (without local in front of it) in createScene?

 

Naomi

Naomi, your a life saver! It works great now.

 

Thanks!

 

Warren

Hey, Warren, you might want to read these:

 

http://omnigeek.robmiracle.com/2011/10/14/understanding-scope-for-beginning-programmers/

 

http://www.coronalabs.com/blog/2011/09/21/tutorial-scopes-for-functions/

 

I think there were more about scope, but I haven’t bookmarked them, and the quick google search game me these two above.

 

Anyhow, it’s important to have a good grasp on scope, and I think it will help you a lot along the way.

 

Naomi

Have you tried adding the local chkSaveEmail up top and then create chkSaveEmail (without local in front of it) in createScene?

 

Naomi

Naomi, your a life saver! It works great now.

 

Thanks!

 

Warren

Hey, Warren, you might want to read these:

 

http://omnigeek.robmiracle.com/2011/10/14/understanding-scope-for-beginning-programmers/

 

http://www.coronalabs.com/blog/2011/09/21/tutorial-scopes-for-functions/

 

I think there were more about scope, but I haven’t bookmarked them, and the quick google search game me these two above.

 

Anyhow, it’s important to have a good grasp on scope, and I think it will help you a lot along the way.

 

Naomi