Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Confuse about addEventListener to objects — Gideros Forum

Confuse about addEventListener to objects

edited June 2012 in General questions
Hi all,
I just want to implement simple addEventListener to check what object is clicked:
	local function onTouch(self,event)
		print(self.col)
	end
 
	local token_orange_list = {};
	for i=1,7 do
		token_orange_list[i] = Bitmap.new(Texture.new("image.png"));
		print(token_orange)
		token_orange_list[i]:setAnchorPoint(0.5, 0.5)
		token_orange_list[i]:setPosition(startX +(i-1)*delta ,startY);
		token_orange_list[i]:setScale(0.8,0.8)
		token_orange_list[i].col = i;
		token_orange_list[i]:addEventListener(Event.MOUSE_DOWN, onTouch,token_orange_list[i])		
		firstRowLayer_Orange:addChild(token_orange_list[i])
	end
But when i click to an object, it print out all 7 value (from 7 down to 1)
So can you tell me how to do this?
Thanks!
Coming soon

Comments

  • MellsMells Guru
    edited June 2012
    Hi,

    have you tried Event:stopPropagation()?
    You can check the "Drag Me" example to see it in action.

    Likes: atilim

    twitter@TheWindApps Artful applications : The Wind Forest. #art #japan #apps
    +1 -1 (+1 / -0 )Share on Facebook
  • edited June 2012
    Thanks @Mells,
    Just change onTouch to:
    	local function onTouch(self, event)
    		if self:hitTestPoint(event.x, event.y) then
    			print(self.col)
    			event:stopPropagation()
    		end
    	end
    And it works!
    Thanks for your comment :P
    Coming soon
  • Glad I could help :)
    (If you want to display your code, you can use < pre lang="lua" > Your code </ pre>)
    twitter@TheWindApps Artful applications : The Wind Forest. #art #japan #apps
    +1 -1 (+1 / -0 )Share on Facebook
  • edited June 2012
    Thanks for < pre > tip :D
    Coming soon
Sign In or Register to comment.