Concatenating string to form reference to image

I was trying to optimize/minimize the following code and wanted to concatenate the stage:setFocus code as follows:

  
 stage:setFocus("ball" .. event.target.ballId)  
  

Unfortunately this does not appear to be working as the ball clicked is not getting focus. Is such concatenation possible and if so anyone identify any problems with my attempt?

  
local function onPressBall ( event )  
   
 print ("press ball" .. event.target.ballId)  
   
 local phase = event.phase  
  
 local stage = display.getCurrentStage()  
  
 if "began" == phase then  
  
 if event.target.ballId == 1 then  
  
 stage:setFocus(ball1)  
  
 elseif event.target.ballId == 2 then  
  
 stage:setFocus(ball2)  
  
 end  
  
  
 elseif "ended" == phase then  
  
 stage:setFocus(nil)  
  
 end  
  
  
end  

Thanks

Paul [import]uid: 7863 topic_id: 2221 reply_id: 302221[/import]

This might work (using global namespace):
[lua]stage:setFocus(_G[“ball”…event.target.ballId])[/lua] [import]uid: 4621 topic_id: 2221 reply_id: 6769[/import]

Thanks LiveToConnect - I will give that a go.

Someone also suggested I try

  
 display.getCurrentStage():setFocus( event.target )  
  

So hopefully one of the two will work. [import]uid: 7863 topic_id: 2221 reply_id: 6771[/import]

Just to confirm the following works

[code]

display.getCurrentStage():setFocus( event.target )

[/code] [import]uid: 7863 topic_id: 2221 reply_id: 6772[/import]