[Resolved] for loop into a group

Hey Corona Gurus!

Im trying to create my own sort of tableView here. So far im parsing some json from my server and displaying them on screen. Right now, i can drag each “badge” individually, but i need them in a group so i can move them all together.

Im just having trouble using/understanding groups (and insert) in this case.

  
coupGroup = display.newGroup()  
  
for i,v in pairs(myBadgeArray) do  
 myBadges[i] = display.newImage("images/"..v)  
 myBadges[i]:translate(0,(i-1) \* 100)  
 myBadges[i]:scale(.75,.75)  
 myBadges[i]:setReferencePoint(display.CenterReferencePoint);  
 myBadges[i]:addEventListener("touch", badgeListener)  
 -- coupGroup:insert(myBadges[i]) -- err something like this?  
end  
  

Orrrrrr is there a better way to approach something like this?

I’d appreciate any kind of help at all.

thanks friends! [import]uid: 88004 topic_id: 26373 reply_id: 326373[/import]

That should work fine, your commented out line there - have you already tried it? If so, was there a problem?

Peach :slight_smile: [import]uid: 52491 topic_id: 26373 reply_id: 106945[/import]

oh haha i guess it DID work. The group got set below my background image. ugh so sorry for wasting your time with this.

Now, i can add event listeners to groups like any other object, correct?

Or rather, can i add event listeners to each object in the loop AND to the entire group?

Thanks again Peach! you’re a celebrity! We were talking about you during one of our corona meetups here in honolulu [import]uid: 88004 topic_id: 26373 reply_id: 106949[/import]

Not a waste of time at all- sometimes it takes making a forum post and having a little dialog to get to the bottom of things. (I’ve done the bg in front many times myself ;))

You can indeed add an event listener to the group as well just how you do with other objects - so “yes” to both your questions.

Peach :slight_smile:

PS - Haha, thank you. All good things, I hope! [import]uid: 52491 topic_id: 26373 reply_id: 107081[/import]

Just to keep with standard conventions i would do

for k, v in pairs  

k = key
v = value [import]uid: 84637 topic_id: 26373 reply_id: 107110[/import]

Thanks for the reply Danny! I will work on my best practices [import]uid: 88004 topic_id: 26373 reply_id: 108734[/import]