I try to activate a function (funct02, see below) when objects are “tapped”.
These objects, images in fact, are issued from a random process (funct01) and store in a table.
Funct01 is ok but I can’t activate funct02 when I “tap” objects.
Help would be very much appreciated. What’s wrong?
[lua] local ui = require(“ui”)
local bigTable = { { “s1.png”,“s2.png” } }
local smallTable = { } --store result of random process
local randomImage1 --variable for the first image (random process)
local randomImage2 --for 2nd image
local funct01 = function ( event ) --when btn1 pressed, smallTable is filled
for i = 1, 2 do
local tir1 = math.random( 1, 2 )
smallTable[#smallTable+1] = tir1
end
randomImage1 = bigTable[1] [smallTable[1] ]
img1 = display.newImage ( randomImage1 )
img1.x = 160; img1.y = 200
randomImage2 = bigTable[1] [smallTable[2] ]
img2 = display.newImage ( randomImage2 )
img2.x = 200; img2.y = 200
end
–Btn1
local btn1 = ui.newButton{
default = “btn1.png”,
over = “btn1_over.png”,
onRelease = funct01
}
btn1.x = 160; btn1.y = 240
local funct02 = function ( event ) --when randomImage1 or randomImage2 “tap”
–do something
end
randomImage1:addEventListener ( “tap”, funct02 ) --DOESN’T WORK, WHY?, idem img1 or img2[/lua]
[import]uid: 8970 topic_id: 5289 reply_id: 305289[/import]