PDA

View Full Version : Translation from AS 2 to AS 3



Pherank
February 16th, 2009, 08:57 PM
I could use some help translating this code:




for (var j = 0; j < columnArr[i].length; j++) {
var mc:MovieClip = this["attachClip_" + num].attachMovie("col_" + num + "_choice", "choice_" + j, j + 1);
}
There's a var named "mc" that will refer to each clip called "attachClip" numbered from 0 to whatever the length of the "columnArr" array is. And each of those attachClip items will (addChild) add an item from the Library (col_1_choice, col_2_choice, col_3_choice, etc). Those are graphic icons that will be made clickable. The AS 2.0 code is nice and compact but I'm not doing a good job of coming up with an AS 3 equivalent.

scottc
February 17th, 2009, 02:20 AM
Avoid using the title "convert as2 to as3", most people who use it paste 1000 lines and expecting someone to convert it from them... however this is only 3 lines (or 1 for that matter), and more like a question.



var mc:MovieClip = new MovieClip(); //container mc?
addChild(mc); //add to stage, or whatever this happens to be.

for (var j:Number = 0; j < columnArr[i].length; j++) { // added :Number datatype on this line
//old code -->> //var mc:MovieClip = this["attachClip_" + num].attachMovie("col_" + num + "_choice", "choice_" + j, j + 1);
//depending on your library/class setup etc you will have to modify the lines
var myChoice:choice = new choice(/*if you have params...*/);
mc.addChild(myChoice); //add inside stage.mc
//choiceArray.push(myChoice); //save a reference for later?
}