The event is triggered by a “touch” Event Listener, and would lead the object’s alpha = 0. Then i want to remove it, but it doesn’t work. would appreciate help in correcting the code
thx
[code]
local fade = function( event )
local phase = event.phase
if “began” == phase then
for i = 1,4 do
transition.to(Rect[i], {time=1000, alpha=0})
if Rect[i].alpha==0 then
Rect[i]:removeSelf() – destroy Rect
end
ok this works slightly different to my timer example
note the t2 part is unecessary i just included it to deomonstrate passing parameters on functions as per above
[lua]local fadeComplete=function(obj, t2)
obj:removeSelf()
print(t2.whatever)
end
local Rect={}
for i = 1,4 do
local rect = display.newRect(i*50,50,50,50)
rect:setFillColor(255,0,0)
Rect[i]=rect
local t – need to set define this in advance to be able to pass reference to fn
– doesn’t seem to be any other way to pass
– parameters at the moment
local fn=function()fadeComplete(rect, t) end
t = transition.to(Rect[i], {time=1000, delay=1000*(i-1), alpha=0.5, onComplete=fn })
– something else we can use in the callback
t.whatever=“whatever”
end [/lua]
i thought you’d be able to do this…
[lua]local fn = fadeComplete
fn.whatever = “whatever”[/lua] but it gives an error [import]uid: 6645 topic_id: 3798 reply_id: 11566[/import]
turns out the “event” passed to fadeComplete is actually the object undergoing transition… so you can just do this:
[lua]local fadeComplete=function(obj)
obj:removeSelf()
end
local Rect={}
for i = 1,4 do
local rect = display.newRect(i*50,50,50,50)
rect:setFillColor(255,0,0)
Rect[i]=rect
transition.to(Rect[i], {time=1000, delay=1000*(i-1), alpha=0.5, onComplete=fadeComplete })
end [/lua] [import]uid: 6645 topic_id: 3798 reply_id: 11570[/import]