How to use a variable as a property in transition

Hi, is there any way to pass a variable for the property to be transitioned?

[code]

local myRectangle = display.newRect(0, 0, 150, 50)
myRectangle.strokeWidth = 3
myRectangle:setFillColor(140, 140, 140)
myRectangle:setStrokeColor(180, 180, 180)

–does not work
–[[
local transitionProperty = alpha

transition.to( myRectangle , {time=400, transitionProperty = 0 , transition=easing.outExpo })
–]]

–does not work
–[[
transitionProperty = “alpha”

transition.to( myRectangle , {time=400, transitionProperty = 0 , transition=easing.outExpo })
–]]

–does work, obviously :slight_smile:
transition.to( myRectangle , {time=400, alpha= 0 , transition=easing.outExpo })

[/code] [import]uid: 50154 topic_id: 12302 reply_id: 312302[/import]

Yes, although I can’t work out what you are doing exactly above.

As an example, if you had a variable for transTime = 1000 you could pass it by doing this;

[lua]transition.to(myRectangle{time = transTime, x = 100, y = 100})[/lua]

Make sense?

Thanks for using Lua tags to post your code; when people don’t it’s a real pain :wink: [import]uid: 52491 topic_id: 12302 reply_id: 44794[/import]

Hi Peach, thanks for your reply, however I’m not trying to pass a value for a property

ie

local myval = 100  
  
transition.to(myRectangle{time = 100, x= myval})  

I’m instead trying to pass a property type to the transition

  
local myprop= x  
  
local myval = 100  
  
transition.to(myRectangle{time = 100, myprop = myval})  

Any ideas?
[import]uid: 50154 topic_id: 12302 reply_id: 44797[/import]

I figured it out!

[code]
local myRectangle = display.newRect(0, 0, 150, 50)
myRectangle.strokeWidth = 3
myRectangle:setFillColor(140, 140, 140)
myRectangle:setStrokeColor(180, 180, 180

local transData= {}

transData.time=400
transData.transition=easing.outExpo

if(somecondition~=true) then
transData.x=0
else
transData.y=0
end

transition.to( myRectangle , transData)

[/code] [import]uid: 50154 topic_id: 12302 reply_id: 44800[/import]

D’oh! Sorry, I completely misunderstood.

… I really should stop forum lurking when I’m not all caffeinated :wink: [import]uid: 52491 topic_id: 12302 reply_id: 44964[/import]