It looks like you're new here. If you want to get involved, click one of these buttons!
MyClass = Core.class(Sprite) function MyClass:init() self:addEventListener(Event.MOUSE_DOWN, self.handler, self) end function MyClass:handler() local children = self:getNumChildren() for i = 1, children do local sprite = self:getChildAt(i) print(sprite) end end MyExtendedClass = Core.class(MyClass) function MyExtendedClass:add(elem) self:addChild(elem) end local container = MyExtendedClass.new() stage:addChild(container) container:add(Bitmap.new(Texture.new("crate.png"))) container:add(Bitmap.new(Texture.new("crate.png"))) container:add(Bitmap.new(Texture.new("crate.png"))) container:add(Bitmap.new(Texture.new("crate.png"))) |
Comments
http://www.nightspade.com
But let's wait and see what @atilim has to say. I'm not saying it is a bug, maybe it was not suppose to work that way, I just want to know if it so, I would simply stop wasting my time and look for other solution
Like static methods and retrieving event target, or something similar
This is because of there are two different selfs when you inherit multiple times. @ar2rsawseen, most probably you remember this thread: http://www.giderosmobile.com/forum/discussion/834/possible-bug-self-in-base-class-init-function-is-not-equal-to-self-in-the-derived-class-init
The exact solution is dropping the deep copying and always make sure that there is always one self. And in your specific example, the solution is moving the line
@ndoss said that two different selfs can cause subtle & difficult to find problems and this is a great example of it.
Similar to your example, this code also crashes exactly with the same reason:
thank you
Ok thanks, moving addEventListener helps and everything works as expected
here is the old Core.class function:
and here is the new one:
#MakeABetterGame! "Never give up, Never NEVER give up!" - Winston Churchill
Likes: techdojo