all groups > flash actionscript > july 2005 >
You're in the

flash actionscript

group:

looping through attachMovie


looping through attachMovie vncntj
7/26/2005 9:14:28 PM
flash actionscript:
I'm trying to loop through a library of MovieClips...

var i:Number = 0;
var j:Number = 0;
onEnterFrame = function () {
if (j<2) {
j++;
var Line = createEmptyMovieClip("Line", 3);
var noo:MovieClip = Line.attachMovie("mc1", "Lines", 3);
if (i<100) {
i++;
noo._x = noo._x+i;
trace(noo._x);
trace(i);
if (i<50) {
i++;
noo._alpha = i;
} else {
noo._alpha = noo._alpha-i;
}
}
}
};
Re: looping through attachMovie Randy1969
7/26/2005 9:26:39 PM
Re: looping through attachMovie QuivalenSoth
7/27/2005 12:00:00 AM
I dont think using onEnterFrame() to check if statements is the best way to do
this - why not use a 'for' statement?

for(j=0; j<2; j++) {
//code
}

--

Looking at your functions, you're attaching a movieclip and moving the _x over
1 pixel, your first 50 clips go from _alpha 0 to _alpha 50, otherwise when i
hits 51, the _alpha will then go back to 0.

Another problem I see is you're setting the _x to the noo:MovieClip (which
doesn't exist on the stage) you need to set it to "Lines". You do realise also
that you're only changing one MovieClip on the stage called "Lines" ? Do you
want more than 1 clip on there? Lines+j ?

Also I would look at writing a 'for' statement, maybe a 'for in' - for (_alpha
in _root.Lines).

When looping through a collection, use 'for' to do this, and use 'if' only to
check conditions and not to check loop.

PK
AddThis Social Bookmark Button