Code snippet

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

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

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


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.


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

I think that is what you are trying to do.

or a dictionnary

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