How can you check if an object has focus?

During a touch event I can call display.getCurrentStage():setFocus(object) so that following touch events all apply to the object. During a touch event how can I check if focus is set to any object?

What I want to do is ‘release’ the object when the users finger moves out of the object bounds, which I do using display.getCurrentStage():setFocus(nill). However while the event is still in the “moved” phase I need to set focus to the next object once the previous object has been ‘released’.

The following unfinished code might help explain.

function card:touch(event)  
 if event.phase == "began" then  
 display.getCurrentStage():setFocus( card )  
 -- display selection  
 elseif event.phase == "moved" then  
 if focusIsSet???? then  
 if card.isOutOfBounds(event) then  
 display.getCurrentStage():setFocus(nil)  
 -- clear selection  
 return false  
 end  
 else  
 display.getCurrentStage():setFocus( card )  
 -- display selection  
 elseif event.phase == "ended" then  
 display.getCurrentStage():setFocus(nil)  
 -- clear selection  
 end  
  
 return true  
end  

Thanks
Chris [import]uid: 36548 topic_id: 18021 reply_id: 318021[/import]

[lua]function card:touch(event)
if event.phase == “began” then
display.getCurrentStage():setFocus( card )
event.target.isFocus = true
– display selection
elseif event.phase == “moved” then
if event.target.isFocus then
if card.isOutOfBounds(event) then
display.getCurrentStage():setFocus(nil)
– clear selection
return false
end
else
display.getCurrentStage():setFocus( card )
– display selection
elseif event.phase == “ended” then
display.getCurrentStage():setFocus(nil)
event.target.isFocus = false
– clear selection
end

return true
end[/lua]
:slight_smile: [import]uid: 12482 topic_id: 18021 reply_id: 68855[/import]

Great, thanks.

I can see I’m going to have to break free of the static language mindset. [import]uid: 36548 topic_id: 18021 reply_id: 68856[/import]