Touch Listner runs but Tap listner causing Assertion errors

Hi,  I am writing an app that has two listners, one for touch events and one for tap events.   The touch listener function works fine but when I try to add a listener to deal with taps on buttons they give an assertion errors.  Here are the snippets.

local background = display.newImageRect( “bg.png”, 480, 320 )

local greenButton = display.newImage(“greenButton.png”, 400, 230)
local redButton = display.newImage(“redButton.png”, 20, 230)

the local onTouch(event) function works fine with this call

background:addEventListener( “touch”, onTouch)  

Here is the tap listner function:

local function tapListener( event )
   local object = event.target
   print( object.name…" TAPPED!" )
end

I call it like this:

greenButton:addEventListener(“tap”, tapListener)
redButton:addEventListener(“tap”, tapListener)

When I launch it in the simulator I get this error:

Runtime error
assertion failed!
stack traceback:
        [C]: in function ‘assert’
        ?: in function ‘getOrCreateTable’
        ?: in function ‘addEventListener’
        ?: in function ‘addEventListener’

It refers to the line which contains the first tap listener call.

This one has me stumped.  Be most grateful for any insight.

Thanks

Hi @guyduff,

My guess is that there’s a scope issue, but we’d have to see the whole thing to determine (not just snippets).

Thanks,

Brent

you were right.  A scope issue.  Found the problem.  Basically I just needed to move a few lines of code around.
 

Hi @guyduff,

My guess is that there’s a scope issue, but we’d have to see the whole thing to determine (not just snippets).

Thanks,

Brent

you were right.  A scope issue.  Found the problem.  Basically I just needed to move a few lines of code around.