Welcome, Guest
Want to take part in these discussions? Sign in if you have an account, or apply for one below
-
- CommentAuthorTheDude
- CommentTimeNov 10th 2008
First, some code:
----------------
var renderer:PixelRenderer ;
var emitterCount:int=0;
var eArray:Array = new Array();
function Explode(ob:MovieClip, vx, vy)
{
//positions the Renderer around the object/emitter
var gb:Point = globalPosition(ob);
var rect1:Rectangle = new Rectangle(0, 0, stage.stageWidth, stage.stageHeight );
rect1.offset(-scene.x, -scene.y);
renderer = new PixelRenderer(rect1);
//Add whatever filters you need for the renderer here.
var bb:BlurFilter = new BlurFilter( 2, 2, 1 );
renderer.addFilter(bb);
//scene displayobject for emitters
scene.addChild( renderer );
var emitter:Emitter2D = new Emitter2D();
eArray.push(emitter);
eArray[emitterCount].counter = new Blast( 300 );
eArray[emitterCount].addInitializer( new SharedImage( new Line( 2 ) ) );
eArray[emitterCount].addInitializer( new Lifetime( 0.2,1.2 ) );
eArray[emitterCount].addInitializer( new ColorInit( 0x00000000,0x00000000 ) );
eArray[emitterCount].addAction( new Age( Quadratic.easeIn) );
eArray[emitterCount].addAction(new ColorChange(0xFFFF3300, 0xFFFFFF00));
eArray[emitterCount].addAction( new Move() );
eArray[emitterCount].addInitializer( new Position( new DisplayObjectZone( ob, renderer )) );
eArray[emitterCount].addInitializer( new Velocity( new DiscZone( new Point( vx*10,vy*10 ), 200, 0)));
eArray[emitterCount].addAction( new RandomDrift( 15, 15 ) );
renderer.addEmitter(eArray[emitterCount] );
eArray[emitterCount].start( );
//GARBAGE DISPOSAL
eArray[emitterCount].addEventListener( EmitterEvent.EMITTER_EMPTY, kill_particles );
emitterCount++;
};
function kill_particles( ev:EmitterEvent ):void
{
ev.target.stop();
renderer.removeEmitter( Emitter2D( ev.target ) );
ev.target.removeEventListener( EmitterEvent.EMITTER_EMPTY, kill_particles );
ev = null;
scene.removeChild(renderer);
renderer = null;
}
The above works terrifically well until the Explode function is called more than once in a short duration of time- before the particles from the previous explosion are finished and the emitter has not triggered the EMITTER_EMPTY event.
I thought that storing the emitters in an array would work but nope, I get particle freeze and an error message.
Can anybody see anything obviously wrong with the code or offer a alternative solution? -
- CommentAuthorRichard
- CommentTimeNov 10th 2008
What is the error message? -
- CommentAuthorTheDude
- CommentTimeNov 11th 2008
Error #1009: null Cannot access a property or method of a null object reference
at bhunternew_fla::MainTimeline/kill_particles()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at org.flintparticles.common.emitters::Emitter/update()
at org.flintparticles.common.emitters::Emitter/updateEventListener()
at flash.events::EventDispatcher/dispatchEventFunction()
at flash.events::EventDispatcher/dispatchEvent()
at org.flintparticles.common.utils::FrameUpdater/frameUpdate() -
- CommentAuthorRichard
- CommentTimeNov 11th 2008
killParticles is clearing and setting to null the latest renderer, not the renderer used by that emitter. i.e. it clears the second renderer when it should clear the first. -
- CommentAuthorTheDude
- CommentTimeNov 12th 2008
hey i think i sorted it. i initiated a PixelRenderer var within the function and pushed it into an array. then in killparticles I pop out the first element every time. So far so good. Till next time.
1 to 5 of 5
