More information about the Underscore mailing list

[_] concatenation in a for loop (AS2)

Simon Johnson simon at lifeisland.net
Tue Aug 21 10:53:28 BST 2007

so_
im creating a set of movieclips on the fly and loading a image from file 
in to each of them

now in this instance ive only got 10 to create but each one itteration 
is 6 lines of almost identical code
so
realy i would like to spawn them all in a for loop
however
the difficulty is in the referencing of the mc's once they are spawned 
to load th image and set their properties
heres some code:

for(var i:Number=0;i<=10;++i){
                
_root.lhand.screenText.createEmptyMovieClip("pinbox"+i,_root.lhand.screenText.getNextHighestDepth())
                
_root.lhand.screenText.$out.createEmptyMovieClip("pin"+i,_root.lhand.screenText.getNextHighestDepth())
                _root.lhand.screenText.pinbox1._x=10;//clearly this will 
only set the _x for the first mc spawned
                _root.lhand.screenText.pinbox1._y=(30+(10*i));// as above
                
_root.lhand.screenText.pinbox1.pin1.loadMovie('../images/scaled_screens/pin.png')
                _root.lhand.screenText.createTextField("text"+i, 
_root.lhand.screenText.getNextHighestDepth(), 30, (30+(10*i)), 100, 
22).text=_root.scape._mPlaces[i]
            }

is there some way to force the compiler to generate a new variable name 
on each iteration ?

TIA

simon