PDA

View Full Version : [AS3] How to convert this from AS2 -> AS3?



Knorcedger
March 2nd, 2007, 01:46 PM
In AS2, i used to write

for(i=0; i<5; i++){
this.createEmptyMovieClip("menu"+i, i);
this["menu"+i].alpha = 50;
}In AS3, i try

public class main extends Sprite{
public function main() {
for(i=0; i<5; i++){
this.["menu"+i] = new MovieClip();
}
}
}but it doesnt work. I get an "Error #1056: Cannot create property menu0 on main."

Can somebody please help me? Tnx in advance.

senocular
March 2nd, 2007, 01:52 PM
make the class dynamic

Knorcedger
March 2nd, 2007, 02:02 PM
Boy... U RULE

tnx once again*100

Dazzer
March 2nd, 2007, 06:03 PM
of course that's not a good way of doing it. Unless senocular corrects me.

You should assign the movieclip to a reference variable, use a hashtable for future references, and then add the movieClip to the displaylist.



public class main extends Sprite
{
public function main():void
{
var myClips:Array = new Array();
for (var i:int = 0; i<10; i++)
{
var temp:MovieClip = new MovieClip();
myClips['menu'+i] = temp;
this.addChild(temp);
}
}
}

eena
August 11th, 2010, 01:38 AM
for(i=0; i<5; i++){
var mc:MovieClip = new MovieClip();
this.addChild(mc);
mc.name ="menu"+i;
mc.alpha = 0.5;
}

for any kind of as2 and as3 doubts send mail to this mail Id"eenaeena@rocketmail.com"
with in one we reply to your mails