Multi Touch help

Guys,

I am trying to use multi touch for the first time.
I did a simple app, with two buttons… its supposed to print the words “Touch Began” and “Touch ended” depending on the phase…

each button works fine seperately… but when I hold one down, while click on the other… sometimes I am missing the Began or ended… what am I missing…

I have included the code below

[code]

system.activate( “multitouch” )

local myText = display.newText(“Test”, 100, 100, native.systemFont, 12)
myText:setTextColor(255, 255, 255)

local function Touch1 (e)

local t = e.target

if (e.phase ==“began”) then

myText.text = myText.text … “\nTouch 1 Began”
display.getCurrentStage():setFocus( t, e.id )

elseif (e.phase ==“ended”) then

myText.text = myText.text … “\nTouch 1 Ended”
display.getCurrentStage():setFocus( t, nil )

end

end

local function Touch2 (e)

local t = e.target

if (e.phase ==“began”) then

myText.text = myText.text … “\nTouch 2 Began”
display.getCurrentStage():setFocus( t, e.id )

elseif (e.phase ==“ended”) then

myText.text = myText.text … “\nTouch 2 Ended”
display.getCurrentStage():setFocus( t, nil )

end

end

local myCircleRight = display.newCircle( 200, 250, 20 )
myCircleRight:setFillColor(128,128,128)
myCircleRight:addEventListener(“touch”, Touch1)

local myCircleLeft = display.newCircle( 50, 250, 20 )
myCircleLeft:setFillColor(128,128,128)
myCircleLeft:addEventListener(“touch”, Touch2)

[/code] [import]uid: 67619 topic_id: 25781 reply_id: 325781[/import]

This appears to be the same kind of problem I mentioned in following blog post:
http://developer.anscamobile.com/forum/2012/04/24/inconsistent-api-stagesetfocus-obj-eventid

There is apparent inconsistency in the way setFocus is implemented depending on whether event.id is sent as argument or not. Still haven’t got any answer about this though… [import]uid: 80100 topic_id: 25781 reply_id: 104238[/import]

I had a look through the sample code… and managed to fix it…
Added the following,

local parent = t.parent  
parent:insert( t )  

and added a return true at the end

Can someone explain to me why adding the parent code actually fixes this?
full code

[code]

system.activate( “multitouch” )

local myText = display.newText(“Test”, 100, 100, native.systemFont, 12)
myText:setTextColor(255, 255, 255)

local function Touch1 (e)

local t = e.target

if (e.phase ==“began”) then

myText.text = myText.text … “\nTouch 1 Began”
local parent = t.parent
parent:insert( t )
display.getCurrentStage():setFocus( t, e.id )

elseif (e.phase ==“ended”) then

myText.text = myText.text … “\nTouch 1 Ended”
display.getCurrentStage():setFocus( t, nil )

end

return true

end

local function Touch2 (e)

local t = e.target

if (e.phase ==“began”) then

myText.text = myText.text … “\nTouch 2 Began”
local parent = t.parent
parent:insert( t )
display.getCurrentStage():setFocus( t, e.id )

elseif (e.phase ==“ended”) then

myText.text = myText.text … “\nTouch 2 Ended”
display.getCurrentStage():setFocus( t, nil )

end

return true

end

local myCircleRight = display.newCircle( 200, 250, 20 )
myCircleRight:setFillColor(128,128,128)
myCircleRight:addEventListener(“touch”, Touch1)

local myCircleLeft = display.newCircle( 50, 250, 20 )
myCircleLeft:setFillColor(128,128,128)
myCircleLeft:addEventListener(“touch”, Touch2)
[/code] [import]uid: 67619 topic_id: 25781 reply_id: 104340[/import]