Explode Image

Flash required: You need version 9 or later of the free Flash player from Adobe to use this content. To download and install the free player from Adobe's web site click here.

Here we use one of Flint’s utility functions to create many small particles from a single image. Then, by applying the Explode activity at the location of the mouse click, we blow the image apart.

package
{
  import org.flintparticles.twoD.actions.DeathZone;
  import org.flintparticles.twoD.actions.Explosion;
  import org.flintparticles.twoD.actions.Move;
  import org.flintparticles.twoD.emitters.Emitter2D;
  import org.flintparticles.twoD.particles.Particle2DUtils;
  import org.flintparticles.twoD.renderers.DisplayObjectRenderer;
  import org.flintparticles.twoD.zones.RectangleZone;

  import flash.display.Bitmap;
  import flash.display.Sprite;
  import flash.events.MouseEvent;
  import flash.geom.Point;
  import flash.text.TextField;

  [SWF(width='500', height='350', frameRate='61', backgroundColor='#000000')]
  
  public class Main extends Sprite
  {
    // width:384 height:255
    [Embed(source="assets/184098.jpg")]
    public var Image1:Class;

    private var emitter:Emitter2D;
    private var bitmap:Bitmap;
    private var renderer:DisplayObjectRenderer;
    
    public function Main()
    {
      var txt:TextField = new TextField();
      txt.text = "Click on the image.";
      txt.textColor = 0xFFFFFF;
      addChild( txt );

      bitmap = new Image1();
      
      emitter = new Emitter2D();
      emitter.addAction( new DeathZone( new RectangleZone( -5, -5, 505, 355 ), true ) );
      emitter.addAction( new Move() );
      var particles:Array = Particle2DUtils.createRectangleParticlesFromBitmapData( bitmap.bitmapData, 10, emitter.particleFactory, 56, 47 );
      emitter.addExistingParticles( particles, false );
      
      renderer = new DisplayObjectRenderer();
      addChild( renderer );
      renderer.addEmitter( emitter );
      emitter.start();
      
      stage.addEventListener( MouseEvent.CLICK, explode, false, 0, true );
    }
    
    private function explode( ev:MouseEvent ):void
    {
      var p:Point = renderer.globalToLocal( new Point( ev.stageX, ev.stageY ) );
      emitter.addAction( new Explosion( 8, p.x, p.y, 500 ) );
    }
  }
}
import org.flintparticles.twoD.actions.*;
import org.flintparticles.twoD.emitters.Emitter2D;
import org.flintparticles.twoD.particles.Particle2DUtils;
import org.flintparticles.twoD.renderers.*;
import org.flintparticles.twoD.zones.RectangleZone;  

var txt:TextField = new TextField();
txt.text = "Click on the image";
txt.textColor = 0xFFFFFF;
addChild( txt );

var emitter:Emitter2D = new Emitter2D();
var particles:Array = Particle2DUtils.createRectangleParticlesFromBitmapData( new Image1(384,255), 10, emitter.particleFactory, 56, 47 );
emitter.addExistingParticles( particles, false );

var renderer:DisplayObjectRenderer = new DisplayObjectRenderer();
renderer.addEmitter( emitter );
addChild( renderer );
emitter.start();

stage.addEventListener( MouseEvent.CLICK, explode, false, 0, true );
    
function explode( ev:MouseEvent ):void
{
  var p:Point = renderer.globalToLocal( new Point( ev.stageX, ev.stageY ) );
  emitter.addAction( new Explosion( 8, p.x, p.y, 500 ) );
  emitter.addAction( new Move() );
  emitter.addAction( new DeathZone( new RectangleZone( -10, -10, 510, 360 ), true ) );
  stage.removeEventListener( MouseEvent.CLICK, explode );
}
<?xml version="1.0" encoding="utf-8"?>
<mx:Application
  xmlns:mx="http://www.adobe.com/2006/mxml"
  xmlns:f="http://flintparticles.org/2009/flint2d"
  layout="absolute" width="500" height="350"
  backgroundColor="#000000" creationComplete="complete()">
  
  <mx:Script>
    <![CDATA[
      import org.flintparticles.twoD.actions.Explosion;
      import org.flintparticles.twoD.particles.Particle2DUtils;
      
      [Embed(source="assets/184098.jpg")]
      public var Image1:Class;

      private function complete():void
      {
        var bitmap:Bitmap  = new Image1();
        var particles:Array = Particle2DUtils.createRectangleParticlesFromBitmapData( bitmap.bitmapData, 10, emitter.particleFactory, 56, 47 );
        emitter.addExistingParticles( particles, false );
        addEventListener( MouseEvent.CLICK, explode, false, 0, true );
      }
      
      private function explode( ev:MouseEvent ):void
      {
        var p:Point = renderer.globalToLocal( new Point( ev.stageX, ev.stageY ) );
        emitter.addAction( new Explosion( 8, p.x, p.y, 500 ) );
      }
    ]]>
  </mx:Script>

<mx:Label text="Click on the image." color="0xFFFFFF"/>
<f:DisplayObjectRenderer id="renderer" width="500" height="350">
  <f:emitters>
    <f:Emitter id="emitter" autoStart="true">
      <f:actions>
        <f:Move/>
        <f:DeathZone zoneIsSafe="true">
          <f:RectangleZone left="-5" right="505" top="-5" bottom="355"/>
        </f:DeathZone>
      </f:actions>
    </f:Emitter>
  </f:emitters>
</f:DisplayObjectRenderer>
</mx:Application>