Flint Actionscript 3 Particle System Example

.swfgeek Logo Particles

Richard Lord has recently released the Version 0.9.4 of Flint.

I made this example
using Flint particle system is an Actionscript 3.0 Open Source project with the aim of create a library that handles the common functionality for all particle systems. To see it work just click anywhere on stage and it will make a nice Firework out of my “Logo”

I just tried it myself and i must say it’s super easy to use and to extend. You can find Flint source on the google code page of Flint with working examples in the downloads section there’s also some very good examples and tutorials on Flint Particle System Site and you can keep track of Richard on his blog.

The latest version comes packed with all kind of particles goodies like:

* Access all properties in Actions, Initializers, Counters and Activities so they can be modified while the emitter is running.
* AlphaInit initializer sets the initial alpha value for all particles
* ImageClasses and SharedImages initializers set the particle image to one selected from a group, with weighting to adjust the selection
* MouseExplosion action pushes particles away from the mouse
* MouseGravity action pulls particles towards the mouse
* TurnAwayFromMouse action causes particles to turn away from the mouse
* GreyscaleZone uses a greyscale image to define a zone, with weighting based on the luminence of each pixel
* Pulse counter emits particles in regular bursts
* PerformanceAdjusted counter adjusts the rate of particle emission if the frame-rate drops
* TwoWay energyEasing functions have an energy peak half-way through the particle’s lifetime

Heres the link to my example using Flint, and Flex 3 as much as I would love to add the code right below my post the IG Syntax HighLighter seems to not be getting very well with the latest update of wordpress so to get the code just right click on my example and it will take you there.

Update you can now view the code right here:

?View Code ACTIONSCRIPT3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package {
 
    import flash.display.Bitmap;
    import flash.display.Sprite;
    import flash.events.MouseEvent;
    import flash.filters.BlurFilter;
    import flash.filters.ColorMatrixFilter;
    import flash.geom.Point;
 
    import org.flintparticles.actions.*;
    import org.flintparticles.counters.*;
    import org.flintparticles.emitters.*;
    import org.flintparticles.energyEasing.Quadratic;
    import org.flintparticles.events.FlintEvent;
    import org.flintparticles.initializers.*;
    import org.flintparticles.zones.*;
 
    [SWF( frameRate='61', backgroundColor='#000000')]
 
    public class LogoFireworks extends Sprite
    {
        [Embed(source="assets/sgw.png")]
 
        public var Logo:Class;
        public var bitmap:Bitmap = new Logo();
        public var ev:FlintEvent;
        private var emitter:PixelEmitter = new PixelEmitter();
 
        public function LogoFireworks()
        {
            ViewSource.addMenuItem(this, "srcview/index.html");
            stage.scaleMode = "noScale";
            stage.align ="TL";
            init();
        }
 
        public function init():void
        {
            stage.addEventListener(MouseEvent.MOUSE_DOWN,startFlint);
            stage.addEventListener(MouseEvent.MOUSE_UP,stopFlint)
        }
        public function prepareToFlint(event:MouseEvent):void
         {
          stage.addEventListener(MouseEvent.MOUSE_DOWN,startFlint);
          stage.addEventListener(MouseEvent.MOUSE_UP,stopFlint)
 
         }
 
        public function startFlint(Event:MouseEvent):void
        {
            emitter.addFilter( new BlurFilter( 2, 2, 1 ) );
            emitter.addFilter( new ColorMatrixFilter( [ 1,0,0,0,0,
                                                        0,1,0,0,0,
                                                        0,0,1,0,0,
                                                        0,0,0,0.96,0 ] ) );
            emitter.setCounter( new Blast( 1500 ) );
            emitter.addInitializer( new ColorInit(Math.random()* 0xFFFF3300,Math.random()* 0xFFFFFF00 ) );
            emitter.addInitializer( new Lifetime( 7) );
            emitter.addInitializer( new Position( new DiscZone( new Point( 0, 0 ), 10 ) ) );
            emitter.addInitializer( new Velocity( new BitmapDataZone( bitmap.bitmapData,-211, -550 ) ) );
            emitter.addAction( new Age( Quadratic.easeIn ) );
            emitter.addAction( new Fade( 1.0, 0 ) );
            emitter.addAction( new Move() );
            emitter.addAction( new LinearDrag( 0.5 ) );
            emitter.addAction( new Accelerate( 0, 70 ) );
            addChild( emitter );
            emitter.x = stage.stageWidth/2;
            emitter.y = stage.stageHeight -(5);
            emitter.start( );
            emitter.addEventListener( FlintEvent.EMITTER_EMPTY, restart);
        }
 
        public function stopFlint(Event:MouseEvent):void
        {
            stage.removeEventListener(MouseEvent.MOUSE_DOWN,startFlint)
        }
 
        public function restart( ev:FlintEvent ):void
        {
            mouseEn();
        }
 
        public function mouseEn():void
        {
            stage.addEventListener(MouseEvent.MOUSE_DOWN,startFlint);
        }
    }
}

Author: Dave Gamez

Digital Craftsman from México and have more than 14 years of experience both in design and development in the digital field. I currently work in web, desktop, mobile and illustration projects alike and spend my time between being Technology Director at Team-O a Digital Studio I co-founded with Cecy Meade and doing consultancy work, when time allows it I like to experiment and tinker with code, animation and illustration.