Thursday, September 29, 2005

Speeding up movieclip.getNextHighestDepth( )

Here's a bit of advice on the Flash ActionScript movieclip.getNextHighestDepth() function. I added that function to Flash Player 7 and it's pretty useful when used correctly. Due to some important size constraints on the Flash Player, the depth searching algorithm is not optimized for recursive descent. That said, a simple optimization can be made to your ActionScript to speed things up.

Consider this code for creating an asteroid field:

for(x = 0, x < 1000, x++)
{
this.createEmptyMovieClip("asteroid", this.getNextHighestDepth());
}


The snippet above can be made faster this way:

var dp = this.getNextHighestDepth();
for(x = 0, x < 1000, x++)
{
this.createEmptyMovieClip("asteroid", dp + x);
}

1 Comments:

At 6:26 AM , Anonymous Chrono said...

With of course the difference that you have to make sure there's nothing in the next 1000 levels...

 

Post a Comment

<< Home