help with class and how it works (the sample list code, specifically)

I downloaded the list class from the sample code, which works great. Now, I’d like to modify the example app so that there are two lists on screen instead of just one, and I’m no good in OO in lua.

The main.lua starts with declaring that List is a class, then there are ten functions which identify how the class operates and is initiated.

Finally, down at the bottom of the code, a list of items is created, which is then used to instantiate a class object:

myList = List({items=items})

I thought, well, I can create my own list:

nList = List({items=items})

and, yeah, it shows up on the screen right beside the original list, just like I want it to.

But the problem is that all events are directed at the original list, regardless of which list is touched.

I don’t want to post code, because its 300 lines of code and my contribution is small… I changed the png image width of the list background to 160px, and added just enough code to declare the second list with a different set of items. So I realize I’m asking a question and not really providing enough info.

But any ideas why the new list doesn’t get events?

Thanks,

Sean.
[import]uid: 4993 topic_id: 1497 reply_id: 301497[/import]

How are you adding the event listeners? For example if you’re adding a touch event listener to object number i in your list you’d want a couple lines in your loop like:
 

local item = nList[i]; item:addEventListener("touch", handleTouch);

Then declare the event listener function ABOVE the loop. If you want it to behave differently based on the item touched, it would be something like

function handleTouch(e) if e.target = nList[3] then print("BUTTON 3 TOUCHED"); end end

How are you adding the event listeners? For example if you’re adding a touch event listener to object number i in your list you’d want a couple lines in your loop like:
 

local item = nList[i]; item:addEventListener("touch", handleTouch);

Then declare the event listener function ABOVE the loop. If you want it to behave differently based on the item touched, it would be something like

function handleTouch(e) if e.target = nList[3] then print("BUTTON 3 TOUCHED"); end end