In case Flash no longer exists; a copy of this site is included in the Flashpoint archive's "ultimate" collection.

Dead Code Preservation :: Archived AS3 works from wonderfl.net

炎のエフェクト

source : http://actionsnippet.com/?p=1750
上記リンク先のコードに無駄を取り入れて若干修正したものです
Dictionary が何なのか良く分かってません・・・
/**
 * Copyright kato ( http://wonderfl.net/user/kato )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/A5Gt
 */

// source : http://actionsnippet.com/?p=1750
// 上記リンク先のコードに無駄を取り入れて若干修正したものです
// Dictionary が何なのか良く分かってません・・・
package {
    //----------------------------------
    // Import Libraries
    //----------------------------------
    import flash.display.Sprite;
    import flash.display.StageAlign;
    import flash.display.StageQuality;
    import flash.display.StageScaleMode;
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.BlendMode;
    import flash.display.GradientType;
    import flash.display.SpreadMethod;
    import flash.filters.BlurFilter;
    import flash.geom.Matrix;
    import flash.geom.Point;
    import flash.utils.Dictionary;
    import flash.events.Event;
    // Import Hi-Res!Stats Library
    import net.hires.debug.Stats;
    
    [SWF(width="465", height="465", backgroundColor="0x000000", frameRate="30")]
    
    public class ParticleFlame extends Sprite 
    {
        // Consts
		// グラデーション作成時に使用
		private const COLORS:Array = [0xFFCC33, 0xFF0000];
		private const ALPHAS:Array = [0.5, 0.8];
		private const RATIOS:Array = [0x00, 0xFF];
		// 2π[rad]
		private const TWO_PI:Number = Math.PI * 2;
        // Vars		
        private var canvas:BitmapData;
        private var overlay:BitmapData;
        private var particles:Dictionary;
        private var blurs:Array /*Filters*/ ;
        
        //------------------------------
        //  Constructor
        //------------------------------
        public function ParticleFlame() 
        {
            stage.align = StageAlign.TOP_LEFT;
            stage.quality = StageQuality.LOW;
            stage.scaleMode = StageScaleMode.NO_SCALE;
            
            init();
        }
        
        //------------------------------
        //  Initialize
        //------------------------------
        private function init():void
        {
			
            canvas = new BitmapData(465, 465, false, 0x000000);
			addChild(new Bitmap(canvas));
			overlay = new BitmapData(465, 465, true, 0x12000000);
			particles = new Dictionary(true);
			blurs = [new BlurFilter(8, 8, 1)];
			addChild(new Stats());
			
			addEventListener(Event.ENTER_FRAME, loopHandler);
        }
        
        //------------------------------
        //  loopHandler
		//------------------------------
		private function loopHandler(event:Event):void
		{
			for(var i:int = 0; i < 3; i++)
			{
				createParticle();
				canvas.copyPixels(overlay, canvas.rect, new Point(0, 0), null, null, true);
			}
		}
		
		//------------------------------
		//  createParticle 
		//------------------------------
		private function createParticle():void
		{
			var p:Particle = new Particle();
			var diameter:Number = Math.random() * 50 + 2;
			var radius:Number = diameter / 2;
			var mat:Matrix = new Matrix();
			
			mat.createGradientBox(diameter, diameter, 0, -radius, -radius);
			p.graphics.beginGradientFill(GradientType.RADIAL, COLORS, ALPHAS, RATIOS, mat, SpreadMethod.PAD);
			p.graphics.drawCircle(0, 0, radius);
			p.velX = 0;
			p.velY = -Math.random() * 5 + 0.5;
			//p.posX = p.x = Math.random() * 100;
			p.posX = stage.mouseX;
			//p.posY = p.y = 200;
			p.posY = stage.mouseY;
			p.theta = Math.random() * TWO_PI;
			p.inc = Math.random() * 0.4 + 0.01;
			p.rad = Math.random() * 2 + 1;
			p.filters = blurs;
			
			particles[p] = p;
			p.addEventListener(Event.ENTER_FRAME, runParticleHandler);
		}
		
		//------------------------------
		//  runParticleHandler
		//------------------------------
		private function runParticleHandler(event:Event):void
		{
			var p:Particle = event.currentTarget as Particle;
			p.posX += p.velX;
			p.posY += p.velY;
			p.velX = p.rad * Math.cos(p.theta);
			p.theta += p.inc;
			p.scaleX = p.scaleY -= 0.03;
			
			if (p.scaleX < 0)
			{
				particles[p] = null;
				p.removeEventListener(Event.ENTER_FRAME, runParticleHandler);
			}
			
			p.x = p.posX;
			p.y = p.posY;
			canvas.draw(p, p.transform.matrix, null, BlendMode.ADD);
		}
    }
}

//--------------------------------------
//
//  Class Particle
//
//--------------------------------------
import flash.display.Sprite;

internal class Particle extends Sprite
{
	public var velX:Number;
	public var velY:Number;
	public var posX:Number;
	public var posY:Number;
	public var theta:Number;
	public var inc:Number;
	public var rad:Number;
	
	public function Particle()
	{
		this.velX = 0;
		this.velY = 0;
		this.posX = 0;
		this.posY = 0;
		this.theta = 0;
		this.inc = 0;
		this.rad = 0;
	}
}