I have made a simple API effect where i create boxes at the middle of the document, and then make them move outwards, and when they're outside the page, i remove them. I create the boxes in a function, then I have an array called movies, which I add the new movieclip to. I move the movies by creating a for loop which is :
for (i=0; i<movies.length; i++) {
movie=movies[i]
But after a while, the framerate slows down, i think this is because the for loop goes goes through every number, even though most of them have been removed. Is there any way to stop that without creating a preset number of boxes before hand. This is my code, just copy and paste all of that onto a frame and you'll see what I mean.
movies = new Array();
pause = false;
addmovie = function (x, y, amount, size) {
for (i=0; i<a mount; i++) {
d = _root.getNextHighestDepth();
_root.createEmptyMovieClip("movie"+d, d);
movie = _root["movie"+d];
with (movie) {
lineStyle(0);
beginFill("0x"+random(999999), random(80)+20);
moveTo(0, -size);
lineTo(size, -size);
lineTo(size, size);
lineTo(-size, size);
lineTo(-size, -size);
lineTo(0, -size);
endFill();
}
movie._x = x;
movie._y = y;
movie.xspeed = Math.random()*10-5;
movie.yspeed = Math.random()*10-5;
movie._xscale = 300;
movie._yscale = movie._xscale;
movie._rotation = Math.atan2(movie.yspeed, movie.xspeed)*52;
movie.time = 0;
movies.push(movie);
}
};
function bound(type, o) {
w = (o._width/2);
h = (o._height/2);
maxx = 550+w;
maxy = 400+h;
minx = -w;
miny = -h;
if (o._x>maxx) {
removeMovieClip(o);
}
if (o._x<minx) {
removeMovieClip(o);
}
if (o._y>maxy) {
removeMovieClip(o);
}
if (o._y<miny) {
removeMovieClip(o);
}
}
onEnterFrame = function () {
if (!pause) {
addmovie(275, 200, 1, _xmouse/100);
for (i=0; i<movies.length; i++) {
movie = movies[i];
movie._x += movie.xspeed;
movie._y += movie.yspeed;
bound(0, movie);
}
}
};
onMouseDown = function () {
pause = true;
};
onMouseUp = function () {
pause = false;
};