Hey all, sorry if the question doesn’t belong here but what I am trying to do is draw rectangles on screen and read user input for them.
They represent numbers 0-9 on a phone, so I want to (like when you are about to make a call and input your numbers, think iPhone the phone graphical user interface) read what the user has pressed, instead of using a textbox and popping up the keyboard.
so I do something like:  
 local arguments =  
 {  
 { id= 1, x= 5, y=194, width=btnWidth, height=btnHeight, alpha= btnDefaultAlpha},  
 { id= 2, x= 218, y=194, width=btnWidth, height=btnHeight, alpha= btnDefaultAlpha},  
 { id= 3, x= 430, y=194, width=btnWidth, height=btnHeight, alpha= btnDefaultAlpha},
… and so on for all 10 of the digits (0-9)
then I do a loop:
 for \_,item in ipairs( arguments ) do  
  
 -- btn attributes set here   
 btnPressed = display.newRect(item.x, item.y, item.width, item.height);  
 btnPressed.id = item.id; -- this should do it, right?  
  
 -- Add the event listener directly to an object  
 btnPressed:addEventListener("touch", btnPressed); -- this only works for the last entry in arguments-table, in my case digit 0  
 end  
and the event:
function btnPressed:touch(e) -- e represents the event to be handled   
 -- which button was pressed?  
 print(e.target.id);  
end;  
Can I even do that, ie pass along the id of the button(rectangle) I am touching?
Regards
BK
[import]uid: 144955 topic_id: 32284 reply_id: 332284[/import]
      
    