This is driving me nuts:
(im new to actionscript btw)
I have created the particle emitter below, but the particles last forever.
How can I remove each particle after it has existed a certain amount of time? (eg. 3secs)
var particleArray:Array = new Array();
var maxParticles:Number = 10;
for (var i:int = 0;i < 20;i++) {
addParticle();
}
function addParticle() {
var dot:Particle = new Particle();
dot.x = hero.mc.x;
dot.y = hero.mc.y-15;
dot.alpha = Math.random() * .8 + .2;
dot.scaleX = dot.scaleY = Math.random() * .8 + .2;
var xMovement:Number = Math.random() * 8 - 4;
var yMovement:Number = Math.random() * 8 - 4;
particleArray.push(dot);
gamelevel.addChild(dot);
if (particleArray.length >= maxParticles) {
gamelevel.removeChild(particleArray.shift());
}
dot.addEventListener(Event.ENTER_FRAME,moveParticle);
function moveParticle()
{
dot.x += xMovement;
dot.y += yMovement;
}
}
Cheers