I have written a small bit of actionscript code which is designed so that small objects fly across a window from left to right at varying speeds, and then get moved back again with different attributes once they reach the right edge. The code is fully functional.
My problem is that this eats a huge amount of system resources, and runs slowly on a 1Ghz machine. Is there a more efficient way to achieve this?
//Frame 1 Code - create 20 objects of varying scale, x/y position and alpha.
dcount = 1;
dupcount = 20;
while (dcount<=dupcount) {
duplicateMovieClip(“arrow”, “arrow_”+dcount, dcount);
setProperty(“arrow_”+dcount, x, random(760)-780);
setProperty("arrow"+dcount, y, random(420)-200);
scalar = random(50)+50;
setProperty("arrow"+dcount, xscale, scalar);
setProperty("arrow"+dcount, yscale, scalar);
setProperty("arrow"+dcount, alpha, random(30)+30);
set("speed"+dcount, random(6)+2);
dcount = dcount+1;
}
//Frame 2 Code - move each object in turn by the random speed that was set initially. Check to see if given object has gone off the right edge of the screen, and if so re-initialize
dcount = 1;
dupcount = 20;
while (dcount<=dupcount) {
xvalueX = getProperty(“arrow_”+dcount, x);
xvalueMod = eval("speed"+dcount);
xvalue = xvalueX+xvalueMod;
setProperty(“arrow_”+dcount, x, xvalue);
if (xvalue >= 840) {
setProperty("arrow"+dcount, x, random(760)-780);
setProperty("arrow"+dcount, y, random(420)-200);
set("speed"+dcount, random(6)+2);
}
dcount = dcount+1;
}
//Frame 3 - Loop to Frame 2
gotoAndPlay(2);
Thanks,
Si