Hmm, I think the documentation is actually correct. See the diagram on the "input events" tab. The event gets to C and is stopped there. It never reaches B. (C is processed before B, reverse order)
Well I tried it out to see what actually happens and the result seems to be different from what the documentation says:
Here's the full code I wrote
TextBox=Core.class(Sprite)function TextBox:init(font,str,width,height,border)local r=Shape.new()if border then
r:setLineStyle(2,0x000000)
r:setFillStyle(Shape.SOLID,0xFFFFFF)end
r:beginPath()
r:moveTo(-width/2,-height/2)
r:lineTo( width/2,-height/2)
r:lineTo( width/2, height/2)
r:lineTo(-width/2, height/2)
r:closePath()
r:endPath()
self:addChild(r)if str thenlocal t=TextField.new(font,str)local w=t:getWidth()local h=t:getHeight()
t:setPosition(-math.floor(w/2),math.floor(h/2))
self:addChild(t)end-- self:addEventListener(Event.ENTER_FRAME,self.update,self)
self:addEventListener(Event.MOUSE_DOWN,self.onMouseDown,self)
self.name=str
endfunction TextBox:update()print("Enter frame=",self.name)endfunction TextBox:onMouseDown(event)print("Mouse Down=",self.name)if self.name=="C"then
event:stopPropagation()endend-----------------------------------------------local A = TextBox.new(nil,"A",50,50,true)local B = TextBox.new(nil,"B",50,50,true)local C = TextBox.new(nil,"C",50,50,true)local D = TextBox.new(nil,"D",50,50,true)local E = TextBox.new(nil,"E",50,50,true)local F = TextBox.new(nil,"F",50,50,true)
A:addChild(B)
A:addChild(C)
B:addChild(D)
B:addChild(E)
C:addChild(F)
stage:addChild(A)
A:setPosition(150,100)
B:setPosition(-40,40)
C:setPosition(40,40)
D:setPosition(-40,40)
E:setPosition(40,40)
F:setPosition(40,40)
The result is attached (as in the documentation). We can see the draw order is
A, B, D, E, C, F
(as expected for a recursive traversal parents drawn before children)
The order for touch events is
F, C, E, D, B, A
(as expected for recursion with children touched before parents -- and children in reverse order)
If stop propagation is run after C is processed (as in the code), then the touch event is processed in
F, C only
So the documentation is not really correct but it gives the right idea. Perhaps it is somewhat oversimplified. The Gideros programmer doesn't need to know the exact order, typically.
Comments
Likes: antix
https://github.com/gideros/gideros
https://www.youtube.com/c/JohnBlackburn1975
https://github.com/gideros/gideros
https://www.youtube.com/c/JohnBlackburn1975
Here's the full code I wrote
A, B, D, E, C, F
(as expected for a recursive traversal parents drawn before children)
The order for touch events is
F, C, E, D, B, A
(as expected for recursion with children touched before parents -- and children in reverse order)
If stop propagation is run after C is processed (as in the code), then the touch event is processed in
F, C only
So the documentation is not really correct but it gives the right idea. Perhaps it is somewhat oversimplified. The Gideros programmer doesn't need to know the exact order, typically.
https://github.com/gideros/gideros
https://www.youtube.com/c/JohnBlackburn1975
but my mistake helped to clarify things )
Thank for your explanation.
Likes: john26, MoKaLux