For Loop to associate an Array

I created an Array with captions and now I want to make it so when I press one of the buttons it will make the caption appear. For this I have used a For loop.

thumbNailCaption does trace the variables I’ve assigned, but I can’t get thumbNailCaption.textDisp to trace anything like it. No matter how many variations I’ve made, it always comes out undefined! Does anyone know what I’m doing wrong?

stop();

// CREATES AN ARRAY TO HOLD THUMBNAIL COMMENTS
var thumbNailCaption = new Array();
thumbNailCaption[0] = “abc”;
thumbNailCaption[1] = “def”;
thumbNailCaption[2] = “ghi”;

// BUTTON PROPERTIES
for (i = 0; i < 12; i++) {
** this[“thumbNailCaption”+i].textDisp = thumbNailCaption*;**
mcBody.mainBody[“thumbNail”+ i].onRelease = function() { _root.mcBody.mainBody.textCaption.textDisp = this.textDisp;}
}

Are you really using AS3?

I’m using Flash CS3 which is capable of AS3 but I don’t need the end code to be exclusively in AS3. Why do you ask?

I just asked because I was skeptical that the code that you posted would actually work when using AS3.

Anyway, what did you mean when you said that “*thumbNailCaption does trace the variables I’ve assigned, but I can’t get *thumbNailCaption.textDisp to trace anything like it.” ? *thumbNailCaption.textDisp isn’t valid code, of course, and I can’t see anything in the code that looks like that fragment. Where are you putting your trace statements and what do they look like?

Moving to ActionScript 1.0/2.0

Ah, I see. I actually have it set to AS2 since I’m not doing anything complicated and I’m already familiar with it. I guess I should have posted under AS2, but I didn’t want to receive deprecated command lines that wouldn’t work for future code.

The “*thumbNailCaption” was a typo but only in the forum, not on my code. I temporarily placed the Trace statements as follows

// BUTTON PROPERTIES
for (i = 0; i < 12; i++) {
this[“thumbNailCaption”+i].textDisp = thumbNailCaption*;
** trace(thumbNailCaption*); // DOES WORK (Traces out abc, def, ghi)
trace(this[“thumbNailCaption”+i].textDisp); // DOES NOT WORK**

mcBody.mainBody[“thumbNail”+ i].onRelease = function() { _root.mcBody.mainBody.textCaption.textDisp = this.textDisp;}
}

[QUOTE=Soig;2335139]I guess I should have posted under AS2, but I didn’t want to receive deprecated command lines that wouldn’t work for future code.[/QUOTE]

The problem with that line of thinking is that you could get AS3 code that wouldn’t work with AS2. If you’re using AS2 stick to the AS2 forum for the most correct answer :wink:

Fair enough. I’ll keep that in mind for future posts.

[quote=Soig;2335139]Ah, I see. I actually have it set to AS2 since I’m not doing anything complicated and I’m already familiar with it. I guess I should have posted under AS2, but I didn’t want to receive deprecated command lines that wouldn’t work for future code.

The “*thumbNailCaption” was a typo but only in the forum, not on my code. I temporarily placed the Trace statements as follows[/quote]

What is the structure of thumbNailCaption array?

This code should work for you as long as thumbNailCaption array is defined that way.



for (i = 0; i < 12; i++)
{
   mcBody.mainBody["thumbNail"+ i].textDisp = thumbNailCaption*;
   mcBody.mainBody["thumbNail"+ i].onRelease = function() {
       _root.mcBody.mainBody.textCaption.textDisp = this.textDisp;
   }
}