PDA

View Full Version : [AS2 OOP] - Dynamic MCs or TextFields



Flash_Test
April 14th, 2007, 12:23 AM
Hi,
as you'll see with the following snippet of code, I'm rather new to OOP for Flash.
I've been trying to dynamically create a textField with no luck.


//mcPath:MovieClip is a parameter passed to the class' constructor
var myArray:Array = new Array("one", "two", "three");
for (var i=0; i>myArray.length; i++) {
var eval("myMc_" + i):MovieClip = mcPath.createTextField("tempText" + i, mcPath.getNextHighestDepth(), 9, 30, 552, 0);
}

The problem is that I get an error: (Syntax error)
Any help would be very much appreciated. Thanks

ps. I did look around, but couldn't find anything that could be of help to my problem. I'm sorry if this issue has already been dealt in the pass.

bcline
April 14th, 2007, 12:47 AM
a couple of problems - you can't do



var eval("myMc_" + i):MovieClip;


that way will always through an error. Try this instead.



this["myMc_"+i] =


Also, you've got the wrong operator for your for loop, it should be -



for (var i=0; i<myArray.length; i++)


That should get you started.

Flash_Test
April 14th, 2007, 01:29 AM
this["myMc_"+i] =
thought I had tried that already, but apparently not.
It's now working thanks to you.
cheers