hey there.
i would like to place various instances of the same library object on the stage.
the different instances (0,1,2,…) are meant to be containers for their individual content. hence, each instance (0,1,2,…) is one container and each containter embeds different placeholders (textfields- and image-instances) in itself.
var distance = 70;
// y-distance between placed objects
var amount = 3;
// number of instances to be placed on the stage
var imgArray:Array = [];
var work:WorkSlot = new WorkSlot();
// linked to MovieClip-object in library (linkage)
for(var i=0; i<amount; i++)
{
imgArray.push(work);
addChild (imgArray*);
imgArray*.y = i*distance;
trace(imgArray*.y);
// 0, 70, 140
/*
var mc:MovieClip = new MovieClip();
imgArray* = mc;
mc.y = i*distance;
*/
}
trace(imgArray[0].y); // 140 (should be "0")
trace(imgArray[1].y); // 140 (should be "70")
trace(imgArray[2].y); // 140
imgArray[0].h1.text = "Title Test 0";
imgArray[1].h1.text = "Title Test 1";
imgArray[2].h1.text = "Title Test 2";
// the last ".text" is placed ("Title Teest 2")
// by putting "imgArray[1].h1.text" at last, "Title Test 1" is shown
the challenge:
on the one hand it’s important to create the number of instances (using the variable “amount”) dynamically, on the other hand it’s important to access the different instances to modify their contents, i.e. text (using
imgArray[1].h1.text="…).
the problem:
in my code above, only the last instance is being placed at 140px (distance=70; last i for for-cycle = 2; .y = i*distance).
the element in the for-loop will be overwritten all the time the loop starts over again… how could i prevent it from overwritting? all three instances have to be placed and accessed. maybe by creating instances and putting the different imgArray* in it?
something like this?
mc0.imgArray[0]
mc*.imgArray* ?
- any ideas to solve it?
- in general: do you guys think an array and a for-loop is the right choice for this kind of stuff?
thank you so much!!