Skip to main content
Participant
February 11, 2008
Answered

Looping and attachMovie()

  • February 11, 2008
  • 4 replies
  • 403 views
This code is supposed to generate a grid of thumbnails. For some reason only the last thumbnail shows up (in the correct place).

I've stripped out some code (that changes the image and title); here's the bare bones. I've tried it with and without the thumb = null, btw.

Can anyone tell me what's wrong with the code?
This topic has been closed for replies.
Correct answer clbeech
try using 'counter' as the depth assignment. leave thumb=null; out, not sure why you would want to do that really. addditionally, add 'var' to the loop conditional, as in: for(var i in cats) { ... }

4 replies

clbeech
Inspiring
February 11, 2008
great! you're welcome gormster.
clbeech
Inspiring
February 11, 2008
I was wondering that as well rlc5611, however it looks as though item=cats[] )<--(insert 'i') must be assigning an object reference from the 'cats' array and I would assume that it must have an 'id' prop assigned, but you know what 'assuming' means ... lol!!

February 11, 2008
Yes it is hard to know. But if whether your assumption is right or wrong, the result would still be that only the last mc would be displayed because each previous mc is being replaced by a new mc with exactly the same name (either a valid name or undefined);
February 11, 2008
var thumb:MovieClip = thumbView.attachMovie("mcThumbnail","thumb"+item,this.getNextHighestDepth());

item["id"] has no meaning

But without knowing what you are trying to do, you might want to use "i" instead of "item". The i returns a name of an object whereas item references the object itself.
clbeech
clbeechCorrect answer
Inspiring
February 11, 2008
try using 'counter' as the depth assignment. leave thumb=null; out, not sure why you would want to do that really. addditionally, add 'var' to the loop conditional, as in: for(var i in cats) { ... }