Can't forward reference anymore

Just recently switched back to Director 1.4 and for some odd reason
i cant forward reference anything anymore O.o any ideas? [import]uid: 34663 topic_id: 18911 reply_id: 318911[/import]

can u provide some sample code?? [import]uid: 64174 topic_id: 18911 reply_id: 72881[/import]

Forward referencing problem

Here is a sample of what I am experiencing.

[lua]
new = function ( params )

local localGroup = display.newGroup()

local bg
local tapevent

bg = display.newImage(“bg.png”, true)
bg.xScale = .58 bg.yScale = .58
bg.x = display.contentWidth / 2 bg.y = display.contentHeight / 2
localGroup:insert(bg)

bg:addEventListener( “tap”, tapevent )

function tapevent( event )

print( “touched” )

end
return localGroup

end[/lua]

by declaring my function with local in the beginning i should have access to it anywhere in my code, but for some odd reason its not doing that and i have to move my function ABOVE the addlistener for it to “recognize” it. [import]uid: 34663 topic_id: 18911 reply_id: 72917[/import]

HOOOK! my bad, i understand what i did wrong now, mistake on my part.

If anyone else has issues forward referencing listener functions check to make sure they’re called AFTER being declared in a function. Forgot the code has to run through it all first. Example:

[lua] local localGroup = display.newGroup()
local group = display.newGroup()

local bg
local touch
local go

localGroup:insert( group )



function go()

bg = display.newImage(“bg.png”, true)
bg.xScale = .58 bg.yScale = .58
bg.x = display.contentWidth / 2 bg.y = display.contentHeight / 2
bg:addEventListener( “tap”, touch )
group:insert(bg)

end

function touch( event )

print( “touched” )

end

go()[/lua]

Sorry for the confusion XD [import]uid: 34663 topic_id: 18911 reply_id: 72920[/import]