Access local table or array from within a Listener function such as touch

How do you access a local table within a touch event, such as the “touch” Listener? I am having troubles because the console error I receive says that my value is nil and that there is an error in indexing. Please help!!!

Thanks! [import]uid: 15607 topic_id: 6239 reply_id: 306239[/import]

function new()  
 local myTable = {}  
 myTable ["firstValue"] = 1000  
 local myRect = display.newRect( 10,10,200,200)  
 local myText = display.newText(myTable.firstValue,50,300)  
 local function touchEvent(event)  
 if event.phase == "began" then  
 myTable.firstValue=myTable.firstValue+1000  
 myText.text = myTable.firstValue  
 end  
 end -- touchEvent  
 myRect:addEventListener("touch",touchEvent)  
end -- new   
new()  

every time you touch the rectangle the value is implemented by 1000. [import]uid: 12635 topic_id: 6239 reply_id: 21525[/import]

Here’s a good article on that:
http://developer.anscamobile.com/content/events-and-listeners

[import]uid: 8045 topic_id: 6239 reply_id: 21535[/import]

Thanks guys! I really appreciate your help. My problem was that I had introduced the function before the table in my code and was therefore producing a nil when indexing the table. I didnt think that it mattered, but it does! Thanks for the quick responses:)

[import]uid: 15607 topic_id: 6239 reply_id: 21627[/import]

Instead of a function, you can use the table as the listener:
http://developer.anscamobile.com/forum/2011/01/30/assigning-one-listener-multiple-tap-events#comment-21696 [import]uid: 12108 topic_id: 6239 reply_id: 21699[/import]