A Visual and Social Artist for the Digital Age
Skype: brucelevick.com

Simple AS3 Particles using TweenLite


Particles in AS3 using the TweenLite engine. Code is below, very easy to follow.

needs flash

//import the tween classes
import gs.TweenLite;
import gs.easing.*

//create the container and particles
var particleCotainer:MovieClip = new MovieClip();
var particleArray:Array = new Array();
var particleArrayb:Array = new Array();
var maxParticles:Number = 200;

//add the particle container to the display
addChild(particleCotainer);

//create the function to add the particles
function addParticle(e:Event)
{

    var dot:Particle = new Particle();
    var dotb:Particle = new Particle();
    particleCotainer.x = stage.stageWidth/2;
    particleCotainer.y = stage.stageHeight/2+120;
    dot.scaleX = dot.scaleY = Math.random() * .8 + .2;
    dotb.scaleX = dotb.scaleY = Math.random() * .6 + .1;
    dotb.xMovement = Math.random() * -200;
    dotb.yMovement = Math.random() * -200;
    dot.xMovement = Math.random() * 200;
    dot.yMovement = Math.random() * -200;
    particleArray.push(dot);
    particleArrayb.push(dotb);
    particleCotainer.addChild(dot);
    particleCotainer.addChild(dotb);
    dot.cacheAsBitmap = true;
    dotb.cacheAsBitmap = true;

    //create the movement for each particle
    TweenLite.to(dot, 2, {y:dot.yMovement, x:dot.xMovement, alpha:.5, rotation:90});
    TweenLite.to(dotb, 2, {y:dotb.yMovement, x:dotb.xMovement, alpha:.5, rotation:-90});
    TweenLite.to(dot, 8, {y:200, alpha:0, rotation:90, delay:1.5, overwrite:0, ease:Strong.easeIn});
    TweenLite.to(dotb, 8, {y:200, alpha:0, rotation:-90, delay:1.5, overwrite:0, ease:Strong.easeIn});

}

//create the timer to call the function. Runs every 100 milliseconds
var myTimer:Timer = new Timer(100);
myTimer.addEventListener(TimerEvent.TIMER, addParticle);
myTimer.start();

Related posts:

2 Comments to “Simple AS3 Particles using TweenLite”

  1. Hi Brusca,

    That looks great and just what I’m looking for, but as I’m new to AS3, can’t work out how to add this into my flash file.

    Do I just put that on frame 1 and have 2 seperate MovieClips in the library with linkage, or have them on the stage and identifiy them there?

    Thanks in advance

  2. Exactly. Place the script on frame 1 and link to the movie clip in the library called “Particle”.

Leave a Reply

Latest Posts

Little Tern Series

I arrived at one of the best wetlands areas in Australia not long ago and was given a brilliant display of acrobatics from the amazing Little Terns that feed in the area. I managed to capture a series of images but ultimately decided on two images that i liked best. Here are those two images and the near frames that I was also considering.