addeventlistener

local rect4 = display.newRect( 0, 0, 50, 50) rect4:setFillColor( 255,0,0 ) rect4:addEventListener( "touch", tr1 ) function tr1 (event)  local counter = 0 transition.to( rect4, {time=1000, alpha=0, x=w-50, y=h-50 }) transition.to( rect4, {time=2000, delay= 1200, alpha=1.0, x=50, y=50 }) counter = counter + 1 label1.text =counter end

can someone tell me why this gives nil:nil error for the eventlistener? I just tried to run the tr1 when I clicked on rect4.

You are trying to use tr1 before you have defined it. You need to define tr1 before using it:

function tr1 (event) ... end rect4:addEventListener( "touch", tr1 )

… or forward declare tr1:

local tr1 rect4:addEventListener( "touch", tr1 ) tr1 = function(event) ... end
local rect4 = display.newRect( 0, 0, 50, 50) rect4:setFillColor( 255,0,0 ) function rect4:touch (event)  local counter = 0 transition.to( rect4, {time=1000, alpha=0, x=0, y=0 }) transition.to( rect4, {time=2000, delay= 1200, alpha=1.0, x=100, y=500 }) counter = counter + 1 end rect4:addEventListener( "touch", tr1 )

that did it. thanks…

As a hint, if you define your functions as elements in a table the order you declare them in doesn’t matter! This makes life a lot easier so I suggest you learn doing that right away!

Thanks for your replies. After some digging in the forums and website, I decided to switch to a different environment, as my immediate needs are business apps. I couldn’t find a step by step walkthrough for a business app, and it would take too long for me to search for workarounds for simple text objects. Thanks for your help.

Hey Viperciyes,

Although I don’t have any personal experience regarding business apps, I have been using Corona for a couple of years now building games. I love Corona, but I think that if your goal is making business apps right from the start, you probably are better off with another framework.

Lol Corona is made to make buisness app as well and pretty fast and nice, don’t get discouraged. You can’t find as well a step by step for a game or a really short one for small game  :stuck_out_tongue: . Not everyone have the same needs, depending on the app.

You are trying to use tr1 before you have defined it. You need to define tr1 before using it:

function tr1 (event) ... end rect4:addEventListener( "touch", tr1 )

… or forward declare tr1:

local tr1 rect4:addEventListener( "touch", tr1 ) tr1 = function(event) ... end
local rect4 = display.newRect( 0, 0, 50, 50) rect4:setFillColor( 255,0,0 ) function rect4:touch (event)  local counter = 0 transition.to( rect4, {time=1000, alpha=0, x=0, y=0 }) transition.to( rect4, {time=2000, delay= 1200, alpha=1.0, x=100, y=500 }) counter = counter + 1 end rect4:addEventListener( "touch", tr1 )

that did it. thanks…

As a hint, if you define your functions as elements in a table the order you declare them in doesn’t matter! This makes life a lot easier so I suggest you learn doing that right away!

Thanks for your replies. After some digging in the forums and website, I decided to switch to a different environment, as my immediate needs are business apps. I couldn’t find a step by step walkthrough for a business app, and it would take too long for me to search for workarounds for simple text objects. Thanks for your help.

Hey Viperciyes,

Although I don’t have any personal experience regarding business apps, I have been using Corona for a couple of years now building games. I love Corona, but I think that if your goal is making business apps right from the start, you probably are better off with another framework.

Lol Corona is made to make buisness app as well and pretty fast and nice, don’t get discouraged. You can’t find as well a step by step for a game or a really short one for small game  :stuck_out_tongue: . Not everyone have the same needs, depending on the app.