dweezil
November 22, 2010, 5:41am
1
Hi, my first transition works but on completion doesn’t call the OnComplete function
[blockcode]
transition.to( crossBar, { time=4000, delay=1000, y=display.contentHeight/3, onComplete=doCrossBarUp} )
local function doCrossBarUp()
print(“doCrossBarUp()”)
transition.to( crossBar, { time=4000, delay=1000, y=-12, onComplete=doCrossBarDown} )
end
local function doCrossBarDown()
transition.to( crossBar, { time=4000, delay=1000, y=display.contentHeight/3, onComplete=doCrossBarUp} )
end
[/blockcode] [import]uid: 9371 topic_id: 3859 reply_id: 303859[/import]
jmp909
November 22, 2010, 6:10am
2
your 1st transition doesnt know what your function is yet because it is defined below it.
therefore define your function variable up front. you need to do this when 2 functions call each other since neither can actually be first without referring to the other
[lua]local doCrossBarUp
local doCrossBarDown
transition.to( crossBar, { time=4000, delay=1000, y=display.contentHeight/3, onComplete=doCrossBarUp} )
– note these are actually a local function
– as defined by the variable originally
function doCrossBarUp()
print(“doCrossBarUp()”)
transition.to( crossBar, { time=4000, delay=1000, y=-12, onComplete=doCrossBarDown} )
end
function doCrossBarDown()
transition.to( crossBar, { time=4000, delay=1000, y=display.contentHeight/3, onComplete=doCrossBarUp} )
end[/lua] [import]uid: 6645 topic_id: 3859 reply_id: 11772[/import]
dweezil
November 22, 2010, 7:23am
3
Cool, thanks. Is this the best way to implement this type of behaviour? [import]uid: 9371 topic_id: 3859 reply_id: 11775[/import]