[Resolved] Touch event problems

So I am having trouble with touch events. The following code demonstrates what is happening:

  
local background = display.newRect(100,100,400,400)  
background:setFillColor(255,0,0)  
local bar = display.newRect(100,100,200,200)  
function listener(event)  
 print(event.phase)  
 if(event.phase == "begin") then  
 display:getCurrentStage():setFocus(event.target)  
 elseif(event.phase =="moved") then   
 elseif(event.phase == "ended" ) then  
 display:getCurrentStage():setFocus(nil)   
  
 end  
 return true  
end  
  
  
bar:addEventListener("touch", listener)   
background:addEventListener("touch", listener)   

This code prints the event from within the listener.

First touch the white square and drag off to the left onto the black background. Notice how no end event was fired?

Next touch the white square and drag off to the left onto the red square.

Notice how the end event fired this time?

The red square got my end event!
Why did the white square not get an end event when you drag off from it?
Is this intended?

[import]uid: 106158 topic_id: 26788 reply_id: 326788[/import]

Firstly try fixing this line below from:

[lua]if(event.phase == “begin”) then[/lua]

to:
[lua]if(event.phase == “began”) then[/lua]
hint: the difference is just on changing the simple i of the word begin for the a. .)

[import]uid: 89165 topic_id: 26788 reply_id: 108742[/import]

Thanks,

 lol = true

[lua]Corona Community welcome you! .)[/lua]
Cheers,
Rodrigo. [import]uid: 89165 topic_id: 26788 reply_id: 108747[/import]

Nicely spotted Rodrigo!

Marked as resolved :slight_smile: [import]uid: 52491 topic_id: 26788 reply_id: 108811[/import]

@Peach - Glad to “help” your forum`s “travel” everyday asnwering all devs!

No problem at all. .)
Cheers,
Rodrigo. [import]uid: 89165 topic_id: 26788 reply_id: 108845[/import]