Flash Tutorial

Flash CS3 Particle Effect Tutorial

, Author

7. Randomize the size and opacity. Randomizing the size and opacity of our particles involves just a couple simple lines of code that we’re going to add to our addParticle function. Here is the code:

As you can see, the only new code here is on lines 9 and 10. In line 9, we’re randomizing the opacity so that it results in a number between 0.2 and 1.0. This will result in an opacity level anywhere from 20% to 100%.

On line 10, we’re randomizing the scaleX and scaleY properties in order to change the size of the particle.

Oh, and one more thing! If you want your particle effects to run smoothly, it’s a good idea to tell Flash to cache your movie clips as bitmaps. This will significantly improve the performance of your effect. To do this, simply insert the following line of code somewhere around line 15:

dot.cacheAsBitmap = true ;

The final result should look something like this:

So, as you can see, by making just 2 small changes (randomizing the size and opacity), we were able to transform this from a bland, monotonous effect into something beautiful and organic.

Anyways, I hope you enjoyed this tutorial. And I hope you’ll take the time to play around with these setting a little bit to try to achieve different results. Part of the fun of creating particle effects is experimenting with them and trying out different settings. So play around a little bit, and if you come up with something interesting, please email the results in a zip file to craig {at} schoolofflash.com.