Packageorg.flintparticles.emitters
Classpublic class Emitter
InheritanceEmitter Inheritance flash.events.EventDispatcher

The Emitter class manages the creation and ongoing state of particles. It uses a number of utility classes to customise its behaviour.

An emitter uses Initializers to customise the initial state of particles that it creates, their position, velocity, color etc. These are added to the emitter using the addInitializer method.

An emitter uses Actions to customise the behaviour of particles that it creates, to apply gravity, drag, fade etc. These are added to the emitter using the addAction method.

An emitter uses Activities to customise its own behaviour in an ongoing manner, to make it move or rotate.

An emitter uses a Counter to know when and how many particles to emit.

An emitter uses a Renderer to display the particles on screen.

All timings in the emitter are based on actual time passed, not on frames.

Most functionality is best added to an emitter using Actions, Initializers, Activities, Counters and Renderers. This offers greater flexibility to combine behaviours witout needing to subclass the Emitter itself.

The emitter also has position properties - x, y, rotation - that can be used to directly affect its location in the particle system.



Public Properties
 PropertyDefined by
  counter : Counter
The Counter for the Emitter.
Emitter
  maximumFrameTime : Number
The maximum duration, in seconds, for a single update frame, in seconds.
Emitter
  particleFactory : ParticleFactory
This is the particle factory used by the emitter to create and dispose of particles.
Emitter
  particles : Array
[read-only] The array of all particles created by this emitter.
Emitter
  renderer : Renderer
The Renderer for the Emitter.
Emitter
  rotation : Number
Indicates the rotation of the Emitter, in degrees, within the particle system's coordinate space.
Emitter
  rotRadians : Number
Indicates the rotation of the Emitter, in radians, within the particle system's coordinate space.
Emitter
  spaceSort : Boolean = false
Identifies whether the particles should be arranged into spacially sorted arrays - this speeds up proximity testing for those actions that need it.
Emitter
  spaceSortedX : Array
The array of particle indices sorted based on the particles' horizontal positions.
Emitter
  x : Number
Indicates the x coordinate of the Emitter within the particle system's coordinate space.
Emitter
  y : Number
Indicates the y coordinate of the Emitter within the particle system's coordinate space.
Emitter
Public Methods
 MethodDefined by
  
The constructor creates an emitter.
Emitter
  
addAction(action:Action, priority:Number):void
Adds an Action to the Emitter.
Emitter
  
addActivity(activity:Activity, priority:Number):void
Adds an Activity to the Emitter.
Emitter
  
addDisplayObjects(... objects):void
Adds existing display objects as particles to the emitter.
Emitter
  
addInitializer(initializer:Initializer, priority:Number):void
Adds an Initializer object to the Emitter.
Emitter
  
dispose():void
Cleans up the emitter prior to removal.
Emitter
  
pause():void
Pauses the emitter.
Emitter
  
removeAction(action:Action):void
Removes an Action from the Emitter.
Emitter
  
removeActivity(activity:Activity):void
Removes an Activity from the Emitter.
Emitter
  
removeInitializer(initializer:Initializer):void
Removes an Initializer from the Emitter.
Emitter
  
rendererGlobalToLocal(p:Point):Point
If the emitter's renderer is a display object, this method will calculate a localToGlobal on the point with respect to the renderer.
Emitter
  
rendererLocalToGlobal(p:Point):Point
If the emitter's renderer is a display object, this method will calculate a localToGlobal on the point with respect to the renderer.
Emitter
  
resume():void
Resumes the emitter after a pause.
Emitter
  
runAhead(time:Number, frameRate:Number = 10):void
Makes the emitter skip forwards a period of time with a single update.
Emitter
  
start():void
Starts the emitter.
Emitter
Protected Methods
 MethodDefined by
  
Emitter
  
frameUpdate(time:Number):void
Used internally and in derived classes to update the emitter.
Emitter
Events
 EventSummaryDefined by
   Dispatched when an emitter attempts to update the particles' state but it contains no particles.Emitter
   Dispatched when a particle is created and has just been added to the system.Emitter
   Dispatched when a particle dies and is about to be removed from the system.Emitter
Property detail
counterproperty
counter:Counter  [read-write]

The Counter for the Emitter. The counter defines when and with what frequency the emitter emits particles.

Implementation
    public function get counter():Counter
    public function set counter(value:Counter):void
maximumFrameTimeproperty 
maximumFrameTime:Number  [read-write]

The maximum duration, in seconds, for a single update frame, in seconds.

Under some circumstances related to the Flash player (e.g. on MacOSX, when the user right-clicks on the flash movie) the flash movie will freeze for a period. When the freeze ends, the current frame of the particle system will be calculated as the time since the previous frame, which encompases the duration of the freeze. This could cause the system to generate a single frame update that compensates for a long period of time and hence moves the particles an unexpected long distance in one go. The result is usually visually unacceptable and certainly unexpected.

This property sets a maximum duration for a frame such that any frames longer than this duration are ignored. The default value is 0.5 seconds. Developers don't usually need to change this from the default value.

Implementation
    public function get maximumFrameTime():Number
    public function set maximumFrameTime(value:Number):void
particleFactoryproperty 
particleFactory:ParticleFactory  [read-write]

This is the particle factory used by the emitter to create and dispose of particles. The default value is an instance of the ParticleCreator class that is shared by all emitters. You don't usually need to alter this unless you are not using the default particle type. Any custom particle factory should implement the ParticleFactory class.

Implementation
    public function get particleFactory():ParticleFactory
    public function set particleFactory(value:ParticleFactory):void

See also

particlesproperty 
particles:Array  [read-only]

The array of all particles created by this emitter.

Implementation
    public function get particles():Array
rendererproperty 
renderer:Renderer  [read-write]

The Renderer for the Emitter. The renderer draws the particles.

Implementation
    public function get renderer():Renderer
    public function set renderer(value:Renderer):void
rotationproperty 
rotation:Number  [read-write]

Indicates the rotation of the Emitter, in degrees, within the particle system's coordinate space.

Implementation
    public function get rotation():Number
    public function set rotation(value:Number):void
rotRadiansproperty 
rotRadians:Number  [read-write]

Indicates the rotation of the Emitter, in radians, within the particle system's coordinate space.

Implementation
    public function get rotRadians():Number
    public function set rotRadians(value:Number):void
spaceSortproperty 
public var spaceSort:Boolean = false

Identifies whether the particles should be arranged into spacially sorted arrays - this speeds up proximity testing for those actions that need it.

spaceSortedXproperty 
public var spaceSortedX:Array

The array of particle indices sorted based on the particles' horizontal positions. To persuade the emitter to create this array you should set the spaceSort property to true. Usually, actions that need this set to true will do so in their addedToEmitter method.

xproperty 
x:Number  [read-write]

Indicates the x coordinate of the Emitter within the particle system's coordinate space.

Implementation
    public function get x():Number
    public function set x(value:Number):void
yproperty 
y:Number  [read-write]

Indicates the y coordinate of the Emitter within the particle system's coordinate space.

Implementation
    public function get y():Number
    public function set y(value:Number):void
Constructor detail
Emitter()constructor
public function Emitter()

The constructor creates an emitter.

Method detail
addAction()method
public function addAction(action:Action, priority:Number):void

Adds an Action to the Emitter. Actions set the behaviour of particles created by the emitter.

Parameters
action:Action — The Action to add
 
priority:Number — Indicates the sequencing of the actions. Higher numbers cause an action to be run before other actions. All actions have a default priority which is used if no value is passed in this parameter. The default priority is usually the one you want so this parameter is only used when you need to override the default.
addActivity()method 
public function addActivity(activity:Activity, priority:Number):void

Adds an Activity to the Emitter. Activities set the behaviour of the Emitter.

Parameters
activity:Activity — The activity to add
 
priority:Number — Indicates the sequencing of the activities. Higher numbers cause an activity to be run before other activities. All activities have a default priority which is used if no value is passed in this parameter. The default priority is usually the one you want so this parameter is only used when you need to override the default.
addDisplayObjects()method 
public function addDisplayObjects(... objects):void

Adds existing display objects as particles to the emitter. This allows you, for example, to take an existing image and subject it to the actions of the emitter.

This method moves all the display objects into the emitter's renderer, removing them from their current position within the display list. It will only work if a renderer has been defined for the emitter and the renderer has been added to the display list.

Parameters
... objects — Each parameter is another display object for adding to the emitter. If you pass an array as the parameter, each item in the array should be another display object for adding to the emitter.
addInitializer()method 
public function addInitializer(initializer:Initializer, priority:Number):void

Adds an Initializer object to the Emitter. Initializers set the initial properties of particles created by the emitter.

Parameters
initializer:Initializer — The Initializer to add
 
priority:Number — Indicates the sequencing of the initializers. Higher numbers cause an initializer to be run before other initialzers. All initializers have a default priority which is used if no value is passed in this parameter. The default priority is usually the one you want so this parameter is only used when you need to override the default.
createParticle()method 
protected function createParticle():Particle

Returns
Particle
dispose()method 
public function dispose():void

Cleans up the emitter prior to removal. If you don't call this method, the garbage collector will clean up all the particles in teh usual way. If you use this method, the particles will be returned to the particle factory for reuse.

frameUpdate()method 
protected function frameUpdate(time:Number):void

Used internally and in derived classes to update the emitter.

Parameters
time:Number — The duration, in seconds, of the current frame.
pause()method 
public function pause():void

Pauses the emitter.

removeAction()method 
public function removeAction(action:Action):void

Removes an Action from the Emitter.

Parameters
action:Action — The Action to remove

See also

addAction()
removeActivity()method 
public function removeActivity(activity:Activity):void

Removes an Activity from the Emitter.

Parameters
activity:Activity — The Activity to remove

See also

addActivity()
removeInitializer()method 
public function removeInitializer(initializer:Initializer):void

Removes an Initializer from the Emitter.

Parameters
initializer:Initializer — The Initializer to remove

See also

addInitializer()
rendererGlobalToLocal()method 
public function rendererGlobalToLocal(p:Point):Point

If the emitter's renderer is a display object, this method will calculate a localToGlobal on the point with respect to the renderer. The new point is returned. If the renderer is not a display object then the original point is returned.

Parameters
p:Point

Returns
Point
rendererLocalToGlobal()method 
public function rendererLocalToGlobal(p:Point):Point

If the emitter's renderer is a display object, this method will calculate a localToGlobal on the point with respect to the renderer. The new point is returned. If the renderer is not a display object then the original point is returned.

Parameters
p:Point

Returns
Point
resume()method 
public function resume():void

Resumes the emitter after a pause.

runAhead()method 
public function runAhead(time:Number, frameRate:Number = 10):void

Makes the emitter skip forwards a period of time with a single update. Used when you want the emitter to look like it's been running for a while.

Parameters
time:Number — The time, in seconds, to skip ahead.
 
frameRate:Number (default = 10) — The frame rate for calculating the new positions. The emitter will calculate each frame over the time period to get the new state for the emitter and its particles. A higher frameRate will be more accurate but will take longer to calculate.
start()method 
public function start():void

Starts the emitter. Until start is called, the emitter will not emit any particles.

Event detail
emitterEmptyevent 
Event object type: org.flintparticles.events.FlintEvent

Dispatched when an emitter attempts to update the particles' state but it contains no particles. This event will be dispatched every time the update occurs and there are no particles in the emitter. The update does not occur when the emitter has not yet been started, when the emitter is paused, and after the emitter has been disposed. So the event will not be dispatched at these times.

See the firework example for an example that uses this event.

See also

pause();
dispose();
particleCreatedevent  
Event object type: org.flintparticles.events.FlintEvent

Dispatched when a particle is created and has just been added to the system.

particleDeadevent  
Event object type: org.flintparticles.events.FlintEvent

Dispatched when a particle dies and is about to be removed from the system. As soon as the event has been handled the particle will be removed but at the time of the event it still exists so its properties (e.g. its location) can be read from it.