onComplete fireing before the transition.to is completed

It seems as soon as the transition to is called, the ‘onComplete’ of this function is called, ignoring the delay and time properties. Am I doing anything wrong? 

Example code below: 

-- simple text object local units = display.newText('meter', 100, 100, native.systemFont, 42) -- function to handle transitions local function transitionUnit() -- function to update text local function changeUnitText(theUnit) units.text = theUnit end transition.to(units,{time = 1000, alpha = 0.4,}) -- this transition updates the text before the delay/time expires instead of 'onComplete' transition.to(units,{time = 1000, alpha = 1, delay = 1000,onComplete = changeUnitText('miles')}) end -- tap the text to start the transition. units:addEventListener("tap", transitionUnit)

Hi Crafty,

Yes, you have to wrap your onComplete in a closure, like this:

[lua]

transition.to(units,{time = 1000, alpha = 1, delay = 1000,onComplete = function() changeUnitText(‘miles’) end})

[/lua]

Basically, onComplete must be a *reference* to a function, not a function call.  If you assign onComplete as a function call, as you did, then that function will execute immediately, and whatever it *returns* (if anything; nil in your case) is what would be assigned to onComplete.

  • Andrew

Wow, thanks. I get it now, works perfect :slight_smile:

Hi Crafty,

Yes, you have to wrap your onComplete in a closure, like this:

[lua]

transition.to(units,{time = 1000, alpha = 1, delay = 1000,onComplete = function() changeUnitText(‘miles’) end})

[/lua]

Basically, onComplete must be a *reference* to a function, not a function call.  If you assign onComplete as a function call, as you did, then that function will execute immediately, and whatever it *returns* (if anything; nil in your case) is what would be assigned to onComplete.

  • Andrew

Wow, thanks. I get it now, works perfect :slight_smile: