# Code snippet

**URL:** https://forum.kirupa.com/t/code-snippet/260600
**Category:** Uncategorized
**Created:** [May 17, 2008, 9:10am UTC](https://forum.kirupa.com/t/code-snippet/260600 "2008-05-17T09:10:25Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![Ricmar](https://avatars.discourse-cdn.com/v4/letter/r/ce73a5/32.png) [@Ricmar](https://forum.kirupa.com/u/Ricmar)
#### Post date: [May 17, 2008, 9:10am UTC](https://forum.kirupa.com/t/code-snippet/260600/1 "2008-05-17T09:10:25Z")

</div>

Can anyone help? This piece of code finds that first index of a given letter (a for example) and then loads it into the ‘i’. So if **i=4** It would then load into one of the movieclips \*\*box4\_mc.box4\_txt. \*\*However the code in read seems to be incorrect.

Im quite new to AS3.0 so wondering if a more experience coder can see the problem?  
Hereäs the full code function

function text\_search():void {  
var i:Number = 0;  
first\_letter = answer.indexOf(letter);  
i = first\_letter;  
trace(first\_letter);  
if (first\_letter == -1) {  
trace(“Sorry”);  
} else {  
[COLOR=red]box\*\_mc.box\*\_txt.text = letter;  
[/COLOR] }  
}

---

<div class="post-metadata">

### Author: ![Felixz](https://avatars.discourse-cdn.com/v4/letter/f/ecb155/32.png) [@Felixz](https://forum.kirupa.com/u/Felixz)
#### Post date: [May 17, 2008, 10:18am UTC](https://forum.kirupa.com/t/code-snippet/260600/2 "2008-05-17T10:18:57Z")

</div>

```auto
getChildByName("box"+i+"_mc").getChildByName("box"+i+"_txt").text
//or
[box"+i+"_mc"]["box"+i+"_txt"].text 
///depending on implementation

```

---

<div class="post-metadata">

### Author: ![ajcates](https://yyz1.discourse-cdn.com/flex011/user_avatar/forum.kirupa.com/ajcates/32/2435_2.png) [@ajcates](https://forum.kirupa.com/u/ajcates)
#### Post date: [May 17, 2008, 10:20am UTC](https://forum.kirupa.com/t/code-snippet/260600/3 "2008-05-17T10:20:32Z")

</div>

What you could do is load all the movieclips into an array. And the letters to each clip in a parreale array.

```auto

var myArray:Array = new Array(clip0, clip2, clip3, clip4);
var myOtherArray:Array = new Array("C","L","I","P");

```

Then lets say you want the movie clip for L’s name.

```auto

myArray[myOtherArray.indexOf("L")].name;

```

I think that is what you are trying to do.

---

<div class="post-metadata">

### Author: ![Felixz](https://avatars.discourse-cdn.com/v4/letter/f/ecb155/32.png) [@Felixz](https://forum.kirupa.com/u/Felixz)
#### Post date: [May 17, 2008, 10:22am UTC](https://forum.kirupa.com/t/code-snippet/260600/4 "2008-05-17T10:22:51Z")

</div>

or a dictionnary

---

<div class="post-metadata">

### Author: ![Ricmar](https://avatars.discourse-cdn.com/v4/letter/r/ce73a5/32.png) [@Ricmar](https://forum.kirupa.com/u/Ricmar)
#### Post date: [May 17, 2008, 1:27pm UTC](https://forum.kirupa.com/t/code-snippet/260600/5 "2008-05-17T13:27:33Z")

</div>

Thanks for the help, i’ll have a try with these answers
