# For Loop to associate an Array

**URL:** <https://forum.kirupa.com/t/for-loop-to-associate-an-array/262041>\
**Category:** Uncategorized\
**Created:** [June 2, 2008, 9:08pm UTC](https://forum.kirupa.com/t/for-loop-to-associate-an-array/262041 "2008-06-02T21:08:44Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Soig](https://avatars.discourse-cdn.com/v4/letter/s/eada6e/32.png) [@Soig](https://forum.kirupa.com/u/Soig)\
**Post date:** [June 2, 2008, 9:08pm UTC](https://forum.kirupa.com/t/for-loop-to-associate-an-array/262041/1 "2008-06-02T21:08:44Z")

</div>

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;}  
}

---

<div class="post-metadata">

**Author:** ![krilnon](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/krilnon/32/34_2.png) [@krilnon](https://forum.kirupa.com/u/krilnon)\
**Post date:** [June 2, 2008, 9:13pm UTC](https://forum.kirupa.com/t/for-loop-to-associate-an-array/262041/2 "2008-06-02T21:13:04Z")

</div>

Are you really using AS3?

---

<div class="post-metadata">

**Author:** ![Soig](https://avatars.discourse-cdn.com/v4/letter/s/eada6e/32.png) [@Soig](https://forum.kirupa.com/u/Soig)\
**Post date:** [June 2, 2008, 9:19pm UTC](https://forum.kirupa.com/t/for-loop-to-associate-an-array/262041/3 "2008-06-02T21:19:35Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![krilnon](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/krilnon/32/34_2.png) [@krilnon](https://forum.kirupa.com/u/krilnon)\
**Post date:** [June 2, 2008, 9:48pm UTC](https://forum.kirupa.com/t/for-loop-to-associate-an-array/262041/4 "2008-06-02T21:48:19Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![senocular](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/senocular/32/7217_2.png) [@senocular](https://forum.kirupa.com/u/senocular)\
**Post date:** [June 2, 2008, 10:08pm UTC](https://forum.kirupa.com/t/for-loop-to-associate-an-array/262041/5 "2008-06-02T22:08:10Z")

</div>

Moving to ActionScript 1.0/2.0

---

<div class="post-metadata">

**Author:** ![Soig](https://avatars.discourse-cdn.com/v4/letter/s/eada6e/32.png) [@Soig](https://forum.kirupa.com/u/Soig)\
**Post date:** [June 2, 2008, 10:13pm UTC](https://forum.kirupa.com/t/for-loop-to-associate-an-array/262041/6 "2008-06-02T22:13:49Z")

</div>

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;}  
}

---

<div class="post-metadata">

**Author:** ![senocular](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/senocular/32/7217_2.png) [@senocular](https://forum.kirupa.com/u/senocular)\
**Post date:** [June 2, 2008, 10:23pm UTC](https://forum.kirupa.com/t/for-loop-to-associate-an-array/262041/7 "2008-06-02T22:23:01Z")

</div>

[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 😉

---

<div class="post-metadata">

**Author:** ![Soig](https://avatars.discourse-cdn.com/v4/letter/s/eada6e/32.png) [@Soig](https://forum.kirupa.com/u/Soig)\
**Post date:** [June 2, 2008, 10:36pm UTC](https://forum.kirupa.com/t/for-loop-to-associate-an-array/262041/8 "2008-06-02T22:36:41Z")

</div>

> [@senocular;2335142](#):
>
> 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 😉

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

---

<div class="post-metadata">

**Author:** ![SHIFT\_nismo](https://avatars.discourse-cdn.com/v4/letter/s/bbe5ce/32.png) [@SHIFT\_nismo](https://forum.kirupa.com/u/SHIFT_nismo)\
**Post date:** [June 3, 2008, 12:28am UTC](https://forum.kirupa.com/t/for-loop-to-associate-an-array/262041/9 "2008-06-03T00:28:18Z")

</div>

[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.

```auto

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;
   }
}

```
