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

forked from: SPEC vol.5 投稿用コード

card_action  /////////////////////////////////////
/**
 * Copyright ProjectNya ( http://wonderfl.net/user/ProjectNya )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/zYJB
 */

// forked from Event's SPEC vol.5 投稿用コード
//////////////////////////////////////////////////////
//  forked from Takema.Terai's flash on 2012-7-4  ////
//////////////////////////////////////////////////////
//  card_action  /////////////////////////////////////
//////////////////////////////////////////////////////

package {

    import flash.display.Sprite;
    import flash.display.StageScaleMode;
    import flash.display.StageAlign;
    import flash.events.Event;
    import flash.geom.Rectangle;
    import flash.display.Bitmap;
    import flash.display.Shape;
    import flash.geom.Matrix;
    import flash.display.GradientType;
    import flash.display.SpreadMethod;
    import flash.display.InterpolationMethod;
    import a24.tween.Tween24;
    import a24.tween.Tween24Event;

    [SWF(backgroundColor="#000000", width="465", height="465", frameRate="30")]

    public class Main extends Sprite {
        private var fontloader:FontLoader;
        private var basePath:String = "http://www.project-nya.jp/images/wonderfl/";
        private var fontPath:String = "MyriadProSemibold.swf";
        private var className:String = "MyriadProSemibold";
        private var label:Label;
        private var gradient:Sprite;
        private var se:SoundEffect;
        private static var bgmPath:String = "robotwarrior.mp3";
        private var loaders:Array;
        private var contents:Array;
        private var cards:Array;
        private var assetsPath:String = "http://assets.wonderfl.net/images/related_images/";
        private var backPath:String = "6/6a/6a39/6a39d24903a88ef0e43693fa953fb2aabe242387";
        private var logoPath:String = "d/d3/d3a6/d3a65301bb89f0e7db4ea5b727224b8b944fba97";
        private var sliverPath:String = "c/c3/c3b9/c3b9c082c57786d6d70cd72f342b232942865a1c";
        private var goldPath:String = "f/fc/fcfb/fcfb1f18a586ad79fd30a5c08cb4f267e9714530";
        private var initialized:uint = 0;
        private var container:Sprite;
        private var water:WaterEffect;
        private var eclipse:FlareCircle;
        private var transit:TransitFlare;
        private var twinkle:Twinkle;

        public function Main() {
            //Wonderfl.capture_delay(1);
            stage.scaleMode = StageScaleMode.NO_SCALE;
            stage.align = StageAlign.TOP_LEFT;
            init();
        }

        private function init():void {
            graphics.beginFill(0x000000);
            graphics.drawRect(0, 0, 465, 465);
            graphics.endFill();
            //
            fontloader = new FontLoader();
            fontloader.addEventListener(FontLoader.COMPLETE, ready, false, 0, true);
            fontloader.load(basePath + fontPath, className);
        }
        private function ready(evt:Event):void {
            fontloader.removeEventListener(FontLoader.COMPLETE, ready);
            //
            se = new SoundEffect();
            se.addEventListener(Event.COMPLETE, prepare, false, 0, true);
            se.load(basePath + bgmPath);
        }
        private function prepare(evt:Event):void {
            se.removeEventListener(Event.COMPLETE, prepare);
            //
            label = new Label(464, 200, 100, Label.CENTER);
            label.x = -232;
            label.y = -92;
            label.textColor = 0xFFFFFF;
            label.text = "LEVEL" + String.fromCharCode(13) + "UP!!";
            //label.blendMode = BlendMode.ADD;
            gradient = new Sprite();
            var shape:Shape = new Shape();
            var colors:Array = [0xFFFFCC, 0xCDA82E, 0xFFFFCC, 0xCDA82E, 0xFFFFCC];
            var alphas:Array = [1, 1, 1, 1, 1];
            var ratios:Array = [0, 64, 128, 192, 255];
            var matrix:Matrix = new Matrix();
            matrix.createGradientBox(464, 200, Math.PI/2, 0, 0);
            shape.graphics.beginGradientFill(GradientType.LINEAR, colors, alphas, ratios, matrix, SpreadMethod.PAD, InterpolationMethod.RGB, 0);
            shape.graphics.drawRect(-232, -100, 464, 200);
            shape.graphics.endFill();
            gradient.addChild(shape);
            gradient.addChild(label);
            shape.cacheAsBitmap = true;
            label.cacheAsBitmap = true;
            shape.mask = label;
            gradient.x = 232;
            gradient.y = 232;
            gradient.alpha = 0;
            gradient.visible = false;
            gradient.scaleX = gradient.scaleY = 0.2;
            //
            eclipse = new FlareCircle(new Rectangle(0, 0, 460, 460), 215);
            eclipse.x = 2;
            eclipse.y = 2;
            //
            twinkle = new Twinkle(new Rectangle(0, 0, 400, 400));
            twinkle.x = 32;
            twinkle.y = 32;
            contents = new Array();
            contents.push({content: null, scale: 1, x: 0, y: 0});
            contents.push({content: null, scale: 2, x: 24, y: 26});
            contents.push({content: null, scale: 1, x: 232, y: 232});
            contents.push({content: null, scale: 1, x: 232, y: 232});
            //
            cards = new Array();
            container = new Sprite();
            //
            var imagePaths:Array = new Array();
            imagePaths = [backPath, logoPath, sliverPath, goldPath];
            loaders = new Array();
            for (var n:uint = 0; n < 4; n++) {
                var loader:ImageLoader = new ImageLoader();
                loader.id = n;
                loader.addEventListener(ImageLoader.COMPLETE, loaded, false, 0, true);
                var imagePath:String = assetsPath + imagePaths[n];
                loader.load(imagePath, true);
                loaders.push(loader);
            }
        }
        private function loaded(evt:Event):void {
            var loader:ImageLoader = ImageLoader(evt.target);
            loader.removeEventListener(ImageLoader.COMPLETE, loaded);
            contents[loader.id].content = loader.content;
            initialize();
        }
        private function initialize():void {
            initialized ++;
            if (initialized > 4 - 1) setup();
        }
        private function setup():void {
            for (var n:uint = 0; n < 4; n++) {
                var info:Object = contents[n];
                var content:Bitmap = Bitmap(info.content);
                if (n < 2) {
                    addChild(content);
                    content.scaleX = content.scaleY = info.scale;
                    content.x = info.x;
                    content.y = info.y;
                    content.alpha = 0;
                    content.visible = false;
                }
                if (n == 2) createSlilverCard(content);
                if (n == 3) createGoldCard(content);
            }
            addChild(eclipse);
            //
            water = new WaterEffect(new Rectangle(0, 0, 465, 465), 16);
            addChild(water);
            var matrix:Matrix = new Matrix();
            matrix.scale(2, 2);
            matrix.translate(24, 26);
            water.initialize(contents[1].content, matrix);
            water.alpha = 0;
            water.setup(40, 3);
            water.progress = 1;
            water.blur = 1;
            //
            addChild(container);
            transit = new TransitFlare(cards[13]);
            transit.addEventListener(Event.COMPLETE, transited, false, 0, true);
            addChild(transit);
            transit.x = 232;
            transit.y = 232;
            addChild(twinkle);
            addChild(gradient);
            //
            start();
        }
        private function start():void {
            var tweens1:Array = new Array();
            var tweens2:Array = new Array();
            for (var n:uint = 0; n < 12; n++) {
                var card:Card = cards[n];
                var tween1:Tween24 = Tween24.serial(
                    Tween24.tween(card, 0.1, Tween24.ease.Linear).bright(2.55).fadeIn(), 
                    Tween24.tween(card, 0.6, Tween24.ease.Linear).bright(0)
                ).delay(0.025*n);
                tweens1.push(tween1);
                var tween2:Tween24 = Tween24.parallel(
                    Tween24.tween(card, 0.8, Tween24.ease.QuadOut, {radius: 40}), 
                    Tween24.tween(card, 0.8, Tween24.ease.Linear, {angle: (30*n - 60) + 360})
                );
                tweens2.push(tween2);
            }
            var back:Bitmap = contents[0].content;
            var sliver:Card = cards[12];
            var atween:Tween24 = Tween24.parallel(
                Tween24.func(se.play, 0.8, true), 
                Tween24.serial(
                    Tween24.tween(back, 0.2, Tween24.ease.Linear).fadeIn(), 
                    Tween24.parallel(
                        Tween24.tween(water, 2, Tween24.ease.Linear).fadeIn(), 
                        Tween24.tween(water, 2, Tween24.ease.Linear, {blur: 0}), 
                        Tween24.tween(water, 2, Tween24.ease.QuadIn, {progress: 0})
                    ), 
                    Tween24.parallel(
                        Tween24.parallel.apply(Tween24.parallel, tweens1), 
                        Tween24.func(eclipse.start).delay(0.4)
                    ), 
                    Tween24.parallel.apply(Tween24.parallel, tweens2), 
                    Tween24.tween(sliver, 0.1, Tween24.ease.Linear).bright(2.55).fadeIn(), 
                    Tween24.tween(sliver, 0.2, Tween24.ease.Linear).bright(0), 
                    Tween24.tween(sliver, 0.4, Tween24.ease.QuadIn).rotation(360), 
                    Tween24.tween(sliver, 0.6, Tween24.ease.ElasticOut).scale(2), 
                    Tween24.func(clear), 
                    Tween24.func(transit.start), 
                    Tween24.wait(5)
                ).delay(0.72)
            );
            atween.addEventListener(Tween24Event.UPDATE, update, false, 0, true);
            atween.addEventListener(Tween24Event.COMPLETE, finished, false, 0, true);
            atween.play();
        }
        private function update(evt:Tween24Event):void {
            for (var n:uint = 0; n < 12; n++) {
                var card:Card = cards[n];
                card.update();
            }
        }
        private function finished(evt:Tween24Event):void {
            evt.target.removeEventListener(Tween24Event.UPDATE, update);
            evt.target.removeEventListener(Tween24Event.COMPLETE, finished);
            transit.stop();
        }
        private function transited(evt:Event):void {
            transit.removeEventListener(Event.COMPLETE, transited);
            clear();
            var atween:Tween24 = Tween24.parallel(
                Tween24.tween(gradient, 0.2, Tween24.ease.Linear).fadeIn(), 
                Tween24.tween(gradient, 0.2, Tween24.ease.Linear).fadeOut().delay(0.8), 
                Tween24.tween(gradient, 1.0, Tween24.ease.ExpoInOut).scale(2)
            );
            atween.addEventListener(Tween24Event.COMPLETE, complete, false, 0, true);
            atween.play();
        }
        private function clear():void {
            for (var n:uint = 0; n < 12; n++) {
                var card:Card = cards[n];
                if (container.contains(card)) container.removeChild(card);
            }
        }
        private function complete(evt:Tween24Event):void {
            evt.target.removeEventListener(Event.COMPLETE, complete);
            twinkle.start();
        }
        private function createSlilverCard(content:Bitmap):void {
            for (var n:uint = 0; n < 13; n++) {
                var card:Card = new Card(content.bitmapData);
                container.addChild(card);
                if (n < 12) {
                    card.scaleX = card.scaleY = 0.4;
                    card.radius = 160;
                    card.angle = 30*n - 60;
                    card.update();
                } else {
                    card.x = 232;
                    card.y = 232;
                }
                card.visible = false;
                cards.push(card);
            }
        }
        private function createGoldCard(content:Bitmap):void {
            var card:Card = new Card(content.bitmapData);
            card.scaleX = card.scaleY = 2;
            card.visible = false;
            cards.push(card);
        }
        
    }

}


//////////////////////////////////////////////////
// Cardクラス
//////////////////////////////////////////////////

import flash.display.Sprite;
import flash.display.BitmapData;
import flash.display.Bitmap;

class Card extends Sprite {
    private var bitmapData:BitmapData;
    public var radius:Number = 0;
    public var angle:Number = 0;
    private var radian:Number = Math.PI/180;

    public function Card(bd:BitmapData) {
        bitmapData = bd.clone();
        init();
    }

    private function init():void {
        var content:Bitmap = new Bitmap(bitmapData);
        addChild(content);
        content.smoothing = true;
        content.x = - bitmapData.width/2;
        content.y = - bitmapData.height/2;
    }
    public function update():void {
        x = 232 + radius*Math.cos(angle*radian);
        y = 232 + radius*Math.sin(angle*radian);
    }

}


//////////////////////////////////////////////////
// WaterEffectクラス
//////////////////////////////////////////////////

import flash.display.Sprite;
import flash.display.DisplayObject;
import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.geom.Rectangle;
import flash.geom.Point;
import flash.geom.Matrix;
import flash.filters.DisplacementMapFilter;
import flash.display.BitmapDataChannel;
import flash.filters.DisplacementMapFilterMode;
import flash.filters.BlurFilter;

class WaterEffect extends Sprite {
    private var rect:Rectangle;
    private var noise:PerlinNoise;
    private static var octaves:uint = 2;
    private static var channel:uint = BitmapDataChannel.RED;
    private var speeds:Array;
    private static var point:Point = new Point();
    private var scale:Number = 10;
    private var amplitude:Number = 3;
    private var map:DisplacementMapFilter;
    private var target:DisplayObject;
    private var source:BitmapData;
    private var bitmapData:BitmapData;
    private var size:Number = 0;
    private var _blur:Number = 0;
    private var _progress:Number = 0;

    public function WaterEffect(r:Rectangle, s:Number = 0) {
        rect = r;
        size = s;
        init();
    }

    private function init():void {
        noise = new PerlinNoise(rect, 32, octaves);
        bitmapData = new BitmapData(rect.width, rect.height, true, 0x00000000);
        var content:Bitmap = new Bitmap(bitmapData);
        content.smoothing = true;
        addChild(content);
        setup(scale, amplitude);
    }
    public function initialize(t:DisplayObject, matrix:Matrix = null):void {
        target = t;
        source = new BitmapData(rect.width, rect.height, true, 0x00000000);
        source.lock();
        source.draw(target, matrix, null, null, null, true);
        source.unlock();
        bitmapData.lock();
        bitmapData.draw(source);
        bitmapData.unlock();
    }
    public function setup(s:Number, a:Number):void {
        scale = s;
        amplitude = a;
        speeds = new Array();
        for (var n:uint = 0; n < octaves; n++) {
            var sx:Number = (Math.random() - 0.5)*amplitude;
            var sy:Number = (Math.random() - 0.5)*amplitude + 2.5;
            speeds.push(new Point(sx, sy));
        }
        map = new DisplacementMapFilter(noise, point, channel, channel, scale, scale, DisplacementMapFilterMode.CLAMP);
    }
    public function update():void {
        noise.update(speeds);
        bitmapData.lock();
        bitmapData.applyFilter(source, rect, point, map);
        bitmapData.unlock();
    }
    public function get blur():Number {
        return _blur;
    }
    public function set blur(value:Number):void {
        _blur = value;
        bitmapData.lock();
        bitmapData.applyFilter(bitmapData, rect, point, new BlurFilter(size*value, size*value, 3));
        bitmapData.unlock();
    }
    public function get progress():Number {
        return _progress;
    }
    public function set progress(value:Number):void {
        _progress = value;
        setup(scale*value, amplitude*value);
        update();
    }

}


//////////////////////////////////////////////////
// TransitFlareクラス
//////////////////////////////////////////////////

import flash.display.Sprite;
import flash.display.Shape;
import flash.display.DisplayObject;
import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.geom.Rectangle;
import flash.geom.Matrix;
import flash.events.Event;
import flash.filters.GlowFilter;
import flash.display.BlendMode;

class TransitFlare extends Sprite {
    private var base:Sprite;
    private var target:DisplayObject;
    private var rect:Rectangle;
    private var source:BitmapData;
    private var threshold:Threshold;
    private var bitmap:Bitmap;
    private var burn:Bitmap;
    private var area:Rectangle;
    private var frame:Shape;
    private var flare:FlareMap;
    private var detection:DetectPixels;
    private var map:BitmapData;
    private var matrix:Matrix;
    private var operation:String = Threshold.OPERATION_HIGH;
    private var _threshold:uint = 0x000000;
    private static var speed:uint = 0x020202;
    private static var color:uint = 0x00000000;
    private static var _mask:uint = 0x00FFFFFF;
    private var glow:GlowFilter;
    private static var gColor:uint = 0x663300;
    public static const COMPLETE:String = Event.COMPLETE;

    public function TransitFlare(t:DisplayObject) {
        target = t;
        init();
    }

    private function init():void {
        base = new Sprite();
        addChild(base);
        base.addChild(target);
        rect = new Rectangle(0, 0, target.width+20, target.height+20);
        area = new Rectangle(0, 0, target.width+20,  target.height+100);
        var bitmapData:BitmapData = new BitmapData(rect.width, rect.height, false);
        bitmap = new Bitmap(bitmapData);
        bitmap.x = - target.width/2 - 10;
        bitmap.y = - target.height/2 - 10;
        target.cacheAsBitmap = true;
        bitmap.cacheAsBitmap = true;
        base.addChild(bitmap);
        target.mask = bitmap;
        glow = new GlowFilter(gColor, 1, 8, 8, 4, 2, true, true);
        var fire:BitmapData = new BitmapData(rect.width, rect.height, false);
        burn = new Bitmap(fire);
        base.addChild(burn);
        burn.x = - target.width/2 - 10;
        burn.y = - target.height/2 - 10;
        burn.filters = [glow];
        frame = new Shape();
        frame.graphics.beginFill(0x000000);
        frame.graphics.drawRect(-target.width/2, -target.height/2, target.width, target.height);
        frame.graphics.endFill();
        base.addChild(frame);
        base.mask = frame;
        flare = new FlareMap(area);
        addChild(flare);
        flare.y = - 45;
        detection = new DetectPixels(4);
        map = new BitmapData(target.width, target.height, true, 0x00000000);
        matrix = new Matrix();
        matrix.translate(-10, -10);
    }
    public function start():void {
        target.visible = true;
        var noise:PerlinNoise = new PerlinNoise(rect, 80, 4, 0);
        noise.colorize({r: 1.2, g: 1.2, b: 1.2}, {r: 0x00, g: 0x00, b: 0x00});
        source = noise;
        threshold = new Threshold(source);
        bitmap.bitmapData = threshold;
        burn.bitmapData = threshold;
        _threshold = 0x000000;
        threshold.reset(0x00000000);
        flare.start();
        addEventListener(Event.ENTER_FRAME, transit, false, 0, true);
    }
    public function stop():void {
        removeEventListener(Event.ENTER_FRAME, transit);
        flare.stop();
    }
    private function transit(evt:Event):void {
        _threshold += speed;
        threshold.apply(operation, _threshold, color, _mask);
        if (_threshold > 0xFFFFFF) {
            _threshold = 0xFFFFFF;
            removeEventListener(Event.ENTER_FRAME, transit);
            dispatchEvent(new Event(TransitFlare.COMPLETE));
            threshold.reset();
        }
        map.fillRect(map.rect, 0x00000000);
        map.draw(burn, matrix);
        detection.search(map, new Rectangle(0, 0, target.width, target.height));
        var mapList:Array = detection.pixels();
        var segments:uint = Math.floor(mapList.length/12);
        flare.offset = {x: 10, y: 100};
        flare.setup(6, 3, segments);
        flare.map = mapList;
    }

}


//////////////////////////////////////////////////
// Thresholdクラス
//////////////////////////////////////////////////

import flash.display.BitmapData;
import flash.geom.Rectangle;
import flash.geom.Point;

class Threshold extends BitmapData {
    private var source:BitmapData;
    private static var point:Point = new Point();
    private var operation:String;
    private var _threshold:uint;
    private var color:uint;
    private var mask:uint;
    public static const OPERATION_LOW:String = "<=";
    public static const OPERATION_HIGH:String = ">=";

    public function Threshold(bd:BitmapData, o:String = OPERATION_LOW, t:uint = 0x000000, c:uint = 0x00000000, m:uint = 0xFFFFFFFF) {
        super(bd.rect.width, bd.rect.height, true, 0xFFFFFFFF);
        source = bd;
        apply(o, t, c, m);
    }

    public function apply(o:String, t:uint, c:uint, m:uint):void {
        operation = o;
        _threshold = t;
        color = c;
        mask = m;
        lock();
        reset();
        threshold(source, rect, point, operation, _threshold, color, mask, false);
        unlock();
    }
    public function reset(fill:uint = 0xFFFFFFFF):void {
        fillRect(rect, fill);
    }

}


//////////////////////////////////////////////////
// FlareCircleクラス
//////////////////////////////////////////////////

import flash.display.Sprite;
import flash.events.Event;
import flash.display.Shape;
import flash.geom.Rectangle;

class FlareCircle extends Sprite {
    private var rect:Rectangle;
    private var radius:uint;
    private var shape:Shape;
    private var flare:FlareMap;
    private var detection:DetectPixels;

    public function FlareCircle(area:Rectangle, r:uint) {
        rect = area;
        radius = r;
        init();
    }

    private function init():void {
        shape = new Shape();
        shape.graphics.lineStyle(8, 0xFFFFFF, 0.5);
        shape.graphics.drawCircle(rect.width/2, rect.height/2, radius);
        //addChild(shape);
        shape.x = rect.x;
        shape.y = rect.y;
        flare = new FlareMap(rect);
        addChild(flare);
        flare.x = rect.x + rect.width/2;
        flare.y = rect.y + rect.height/2;
        detection = new DetectPixels(2);
        detection.search(shape, rect, 0x66FFFFFF);
        flare.map = detection.pixels();
        flare.setup(0, 2, 60);
        flare.addEventListener(Event.COMPLETE, complete, false, 0, true);
        //flare.start();
    }
    public function start():void {
        flare.start();
    }
    public function stop():void {
        flare.stop();
    }
    private function complete(evt:Event):void {
        dispatchEvent(new Event(Event.COMPLETE));
    }

}


//////////////////////////////////////////////////
// FlareMapクラス
//////////////////////////////////////////////////

import flash.display.Sprite;
import flash.display.Shape;
import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.events.Event;
import flash.geom.Rectangle;
import flash.geom.Point;
import flash.filters.BlurFilter;
import flash.filters.GlowFilter;
import flash.display.BlendMode;
//import sketchbook.colors.ColorUtil;

class FlareMap extends Sprite {
    private var rect:Rectangle;
    private var fire:Rectangle;
    private var flare:BitmapData;
    private var bitmapData:BitmapData;
    private var bitmap:Bitmap;
    private var rPalette:Array;
    private var gPalette:Array;
    private var bPalette:Array;
    private static var point:Point = new Point(0, 0);
    private var speed:Point = new Point(0, 0);
    private var unit:uint = 2;
    private var segments:uint = 8;
    private var blur:BlurFilter;
    private var maps:Array;
    public var offset:Object = {x: 0, y: 0};
    private var faded:uint = 0;
    public static const COMPLETE:String = Event.COMPLETE;

    public function FlareMap(r:Rectangle) {
        rect = r;
        initialize();
        draw();
    }

    public function setup(s:uint = 6, u:uint = 8, seg:uint = 8):void {
        speed.y = - s;
        unit = u;
        segments = seg;
    }
    public function set map(list:Array):void {
        maps = list;
    }
    private function initialize():void {
        rPalette = new Array();
        gPalette = new Array();
        bPalette = new Array();
        for (var n:uint = 0; n < 256; n++) {
            var luminance:uint = (n < 128) ? n*2 : 0;
            //var rgb:Object = ColorUtil.HLS2RGB(n*360/256, luminance, 100);
            var rgb:Object = HLS2RGB(n*360/256, luminance, 100);
            var color:uint = rgb.r << 16 | rgb.g << 8 | rgb.b;
            rPalette[n] = color;
            gPalette[n] = 0;
            bPalette[n] = 0;
        }
        blur = new BlurFilter(4, 4, 3);
        blendMode = BlendMode.ADD;
    }
    private function draw():void {
        fire = new Rectangle(0, 0, rect.width, rect.height);
        flare = new BitmapData(fire.width, fire.height, false, 0xFF000000);
        bitmapData = new BitmapData(rect.width, rect.height, false, 0xFF000000);
        bitmap = new Bitmap(bitmapData);
        addChild(bitmap);
        bitmap.x = - rect.width/2;
        bitmap.y = - rect.height/2;
    }
    public function start():void {
        addEventListener(Event.ENTER_FRAME, update, false, 0, true);
    }
    public function stop():void {
        removeEventListener(Event.ENTER_FRAME, update);
        faded = 0;
        addEventListener(Event.ENTER_FRAME, clear, false, 0, true);
    }
    private function update(evt:Event):void {
        if (!maps) return;
        flare.lock();
        bitmapData.lock();
        for (var n:uint = 0; n < segments; n++) {
            var id:uint = Math.random()*maps.length;
            var px:int = maps[id].x + offset.x;
            var py:int = maps[id].y + offset.y;
            var range:Rectangle = new Rectangle(px, py, unit, unit)
            flare.fillRect(range, 0xFFFFFF);
        }
        flare.applyFilter(flare, fire, speed, blur);
        bitmapData.paletteMap(flare, rect, point, rPalette, gPalette, bPalette);
        flare.unlock();
        bitmapData.unlock();
    }
    private function clear(evt:Event):void {
        faded ++;
        flare.lock();
        bitmapData.lock();
        flare.applyFilter(flare, fire, speed, blur);
        bitmapData.paletteMap(flare, rect, point, rPalette, gPalette, bPalette);
        if (faded > 20) {
            bitmapData.fillRect(rect, 0x000000);
            removeEventListener(Event.ENTER_FRAME, clear);
            dispatchEvent(new Event(FlareMap.COMPLETE));
        }
        flare.unlock();
        bitmapData.unlock();
    }
    private function HLS2RGB(h:Number, l:Number, s:Number):Object{
        var max:Number;
        var min:Number;
        h = (h < 0)? h % 360+360 : (h>=360)? h%360: h;
        l = (l < 0)? 0 : (l > 100)? 100 : l;
        s = (s < 0)? 0 : (s > 100)? 100 : s;
        l *= 0.01;
        s *= 0.01;
        if (s == 0) {
            var val:Number = l*255;
            return {r:val, g:val, b:val};
        }
        if (l < 0.5) {
            max = l*(1 + s)*255;
        } else {
            max = (l*(1 - s) + s)*255;
        }
        min = (2*l)*255 - max;
        return _hMinMax2RGB(h, min, max);
    }
    private function _hMinMax2RGB(h:Number, min:Number, max:Number):Object{
        var r:Number;
        var g:Number;
        var b:Number;
        var area:Number = Math.floor(h/60);
        switch(area){
            case 0:
                r = max;
                g = min + h * (max - min)/60;
                b = min;
                break;
            case 1:
                r = max - (h - 60)*(max - min)/60;
                g = max;
                b = min;
                break;
            case 2:
                r = min ;
                g = max;
                b = min + (h - 120)*(max - min)/60;
                break;
            case 3:
                r = min;
                g = max - (h - 180)*(max - min)/60;
                b =max;
                break;
            case 4:
                r = min + (h - 240)*(max - min)/60;
                g = min;
                b = max;
                break;
            case 5:
                r = max;
                g = min;
                b = max - (h - 300)*(max - min)/60;
                break;
            case 6:
                r = max;
                g = min + h*(max - min)/60;
                b = min;
                break;
        }
        r = Math.min(255, Math.max(0, Math.round(r)));
        g = Math.min(255, Math.max(0, Math.round(g)));
        b = Math.min(255, Math.max(0, Math.round(b)));
        return {r:r, g:g, b:b};
    }

}


//////////////////////////////////////////////////
// DetectPixelsクラス
//////////////////////////////////////////////////

import flash.display.BitmapData;
import flash.geom.Rectangle;
import flash.geom.Point;
import flash.geom.Matrix;
import flash.display.IBitmapDrawable;

class DetectPixels {
    private var bd:IBitmapDrawable;
    private var rect:Rectangle;
    private var map:BitmapData;
    private var mapList:Array;
    private var accuracy:uint;
    private var threshold:uint = 0x80FFFFFF;
    private var offset:Object = {x: 0, y: 0};

    public function DetectPixels(a:uint = 1) {
        accuracy = a;
    }

    public function search(t:IBitmapDrawable, r:Rectangle, th:uint = 0x80FFFFFF, o:Object = null):void {
        bd = t;
        rect = r;
        threshold = th;
        if (o) offset = o;
        var w:uint = rect.width/accuracy;
        var h:uint = rect.height/accuracy;
        detect(w, h);
    }
    private function detect(w:uint, h:uint):void {
        map = new BitmapData(w, h, true, 0x00000000);
        var matrix:Matrix = new Matrix();
        matrix.translate(-rect.x, -rect.y);
        matrix.scale(1/accuracy, 1/accuracy);
        map.lock();
        map.draw(bd, matrix);
        map.unlock();
        mapList = new Array();
        for (var x:uint = 0; x < w; x++) {
            for (var y:uint = 0; y < h; y++) {
                var color:uint = map.getPixel32(x, y);
                if (color >= threshold) {
                    var px:int = x*accuracy + rect.x + offset.x;
                    var py:int = y*accuracy + rect.y + offset.y;
                    var point:Point = new Point(px, py);
                    mapList.push(point);
                }
            }
        }
    }
    public function pixels():Array {
        return mapList;
    }

}


//////////////////////////////////////////////////
// PerlinNoiseクラス
//////////////////////////////////////////////////

import flash.display.BitmapData;
import flash.geom.Rectangle;
import flash.geom.Point;
import flash.geom.ColorTransform;

class PerlinNoise extends BitmapData {
    private var base:uint;
    private var octaves:uint;
    private var seed:uint;
    private static var point:Point = new Point();
    private var offsets:Array;
    private var color:ColorTransform;
    private var multiplier:Object = {r: 1, g: 1, b: 1};
    private var offset:Object = {r: 0x00, g: 0x00, b: 0x00};

    public function PerlinNoise(rect:Rectangle, b:uint = 20, o:uint = 2, s:uint = 1) {
        super(rect.width, rect.height, false, 0xFF000000);
        create(b, o, s);
    }

    public function create(b:uint, o:uint, s:uint):void {
        base = b;
        octaves = o;
        offsets = new Array();
        for (var n:uint = 0; n < octaves; n++) {
            var point:Point = new Point();
            offsets.push(point);
        }
        seed = s;
        if (seed == 0) seed = Math.floor(Math.random()*1000);
        lock();
        perlinNoise(base, base, octaves, seed, false, true, 0, true, offsets);
        draw(this);
        unlock();
    }
    public function update(speeds:Array):void {
        for (var n:uint = 0; n < octaves; n++) {
            var offset:Point = offsets[n];
            var speed:Point = speeds[n];
            offset.x += speed.x;
            offset.y += speed.y;
        }
        perlin();
    }
    private function perlin():void {
        lock();
        perlinNoise(base, base, octaves, seed, false, true, 0, true, offsets);
        draw(this);
        unlock();
    }
    public function colorize(m:Object, o:Object):void {
        multiplier = m;
        offset = o;
        color = new ColorTransform(multiplier.r, multiplier.g, multiplier.b, 1, offset.r, offset.g, offset.b, 0);
        lock();
        draw(this, null, color);
        unlock();
    }

}


//////////////////////////////////////////////////
// Twinkleクラス
//////////////////////////////////////////////////

import flash.display.Sprite;
import flash.events.Event;
import flash.geom.Rectangle;
import flash.utils.Dictionary;
import flash.utils.Timer;
import flash.events.TimerEvent;

class Twinkle extends Sprite {
    private var rect:Rectangle;
    private var id:uint = 0;
    private var particles:Dictionary;
    private var timer:Timer;
    private static var interval:uint = 20;

    public function Twinkle(r:Rectangle) {
        rect = r;
    }

    public function start():void {
        id = 0;
        particles = new Dictionary(true);
        create();
        timer = new Timer(interval);
        timer.addEventListener(TimerEvent.TIMER, create, false, 0, true);
        timer.start();
        addEventListener(Event.ENTER_FRAME, update, false, 0, true);
    }
    public function stop():void {
        if (timer) {
            timer.stop();
            timer.removeEventListener(TimerEvent.TIMER, create);
            timer = null;
        }
    }
    private function create(evt:TimerEvent = null):void {
        var radius:Number = 15 + Math.random()*15;
        var particle:ParticleLight = new ParticleLight(6, radius);
        addChild(particle);
        particle.id = id;
        particle.x = uint(Math.random()*rect.width);
        particle.y = uint(Math.random()*rect.height);
        particle.rotation = Math.random()*360;
        particles[id] = particle;
        particle.addEventListener(Event.COMPLETE, complete, false, 0, true);
        particle.start();
        id ++;
    }
    private function complete(evt:Event):void {
        var particle:ParticleLight = ParticleLight(evt.target);
        particle.removeEventListener(Event.COMPLETE, complete);
        removeChild(particle);
        delete particles[particle.id];
        particle = null;
    }
    private function update(evt:Event):void {
        var count:uint = 0;
        for (var n:String in particles) {
            if (particles[n]) count++;
        }
        if (count < 1) {
            removeEventListener(Event.ENTER_FRAME, update);
            dispatchEvent(new Event(Event.COMPLETE));
        }
    }

}


//////////////////////////////////////////////////
// ParticleLightクラス
//////////////////////////////////////////////////

import flash.display.Sprite;
import flash.events.Event;
import flash.display.Shape;
import flash.filters.GlowFilter;
import flash.display.BlendMode;
import a24.tween.Tween24;
import a24.tween.Tween24Event;
import frocessing.color.ColorHSV;

class ParticleLight extends Sprite {
    public var id:uint;
    private static var unit:uint = 6;
    private static var radius:uint = 25;
    private static var blur:Number = 16;
    private var color:ColorHSV;
    private var atween:Tween24;

    public function ParticleLight(u:uint = 6, r:uint = 25) {
        unit = u;
        radius = r;
        blur = radius*0.64;
        init();
    }

    private function init():void {
        var hue:Number = Math.random()*360;
        color = new ColorHSV(hue, 0.5);
        draw();
        alpha = 0;
        visible = false;
        scaleX = scaleY = 0;
        blendMode = BlendMode.ADD;
    }
    public function start():void {
        atween = Tween24.serial(
            Tween24.tween(this, 0.3, Tween24.ease.ExpoOut).fadeIn().scale(1), 
            Tween24.tween(this, 1.2, Tween24.ease.QuadOut).fadeOut().scale(0)
        );
        atween.addEventListener(Tween24Event.COMPLETE, complete, false, 0, true);
        atween.play();
    }
    private function complete(evt:Tween24Event):void {
        atween.removeEventListener(Tween24Event.COMPLETE, complete);
        dispatchEvent(new Event(Event.COMPLETE));
    }
    private function draw():void {
        for (var n:uint = 0; n < unit; n++) {
            var shape:Shape = new Shape();
            addChild(shape);
            shape.graphics.beginFill(color.value);
            shape.graphics.moveTo(0, -radius*0.1);
            shape.graphics.curveTo(0, 0, radius, 0);
            shape.graphics.curveTo(0, 0, 0, radius*0.1);
            shape.graphics.endFill();
            shape.rotation = 360/unit*n;
        }
        filters = [new GlowFilter(color.value, 1, blur, blur, 4, 3, false, false)];
    }

}


//////////////////////////////////////////////////
// ImageLoaderクラス
//////////////////////////////////////////////////

import flash.events.EventDispatcher;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.net.URLRequest;
import flash.display.Bitmap;
import flash.events.Event;
import flash.events.IOErrorEvent;
import flash.events.HTTPStatusEvent;
import flash.events.SecurityErrorEvent;
import flash.system.LoaderContext;

class ImageLoader extends EventDispatcher {
    public var id:uint;
    private var loader:Loader;
    private var info:LoaderInfo;
    public var content:Bitmap;
    private var smoothing:Boolean;
    public static const INIT:String = Event.INIT;
    public static const COMPLETE:String = Event.COMPLETE;

    public function ImageLoader() {
        loader = new Loader();
        info = loader.contentLoaderInfo;
    }

    public function load(file:String, s:Boolean = false):void {
        smoothing = s;
        info.addEventListener(IOErrorEvent.IO_ERROR, ioerror, false, 0, true);
        info.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpstatus, false, 0, true);
        info.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityerror, false, 0, true);
        info.addEventListener(Event.INIT, initialize, false, 0, true);
        info.addEventListener(Event.COMPLETE, complete, false, 0, true);
        try {
            //Security.allowDomain("assets.wonderfl.net");
            loader.load(new URLRequest(file), new LoaderContext(true));
        } catch (err:Error) {
            trace(err.message);
        }
    }
    public function unload():void {
        loader.unload();
    }
    private function ioerror(evt:IOErrorEvent):void {
        loader.unload();
        trace(evt.text);
    }
    private function httpstatus(evt:HTTPStatusEvent):void {
        trace(evt.status);
    }
    private function securityerror(evt:SecurityErrorEvent):void {
        trace(evt.text);
    }
    private function initialize(evt:Event):void {
        content = Bitmap(info.content);
        if (smoothing) {
            content.smoothing = true;
        }
        dispatchEvent(new Event(ImageLoader.INIT));
    }
    private function complete(evt:Event):void {
        info.removeEventListener(IOErrorEvent.IO_ERROR, ioerror);
        info.removeEventListener(HTTPStatusEvent.HTTP_STATUS, httpstatus);
        info.removeEventListener(SecurityErrorEvent.SECURITY_ERROR, securityerror);
        info.removeEventListener(Event.INIT, initialize);
        info.removeEventListener(Event.COMPLETE, complete);
        //addChild(loader);
        dispatchEvent(new Event(ImageLoader.COMPLETE));
    }

}


//////////////////////////////////////////////////
// FontLoaderクラス
//////////////////////////////////////////////////

import flash.events.EventDispatcher;
import flash.display.Loader;
import flash.display.LoaderInfo;
import flash.net.URLRequest;
import flash.text.Font;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.events.IOErrorEvent;
import flash.events.HTTPStatusEvent;
import flash.events.SecurityErrorEvent;
import flash.system.ApplicationDomain;
import flash.system.SecurityDomain;
import flash.system.LoaderContext;
import flash.utils.getDefinitionByName;

class FontLoader extends EventDispatcher {
    public var id:uint;
    private var loader:Loader;
    private var info:LoaderInfo;
    private var _className:String;
    private var _font:Font;
    private var _fontName:String;
    private var embeded:Boolean = false;
    public static const IO_ERROR:String = IOErrorEvent.IO_ERROR;
    public static const HTTP_STATUS:String = HTTPStatusEvent.HTTP_STATUS;
    public static const SECURITY_ERROR:String = SecurityErrorEvent.SECURITY_ERROR;
    public static const INIT:String = Event.INIT;
    public static const COMPLETE:String = Event.COMPLETE;

    public function FontLoader() {
        loader = new Loader();
        info = loader.contentLoaderInfo;
    }

    public function load(file:String, name:String, e:Boolean = false):void {
        _className = name;
        embeded = e;
        info.addEventListener(ProgressEvent.PROGRESS, progress, false, 0, true);
        info.addEventListener(IOErrorEvent.IO_ERROR, ioerror, false, 0, true);
        info.addEventListener(HTTPStatusEvent.HTTP_STATUS, httpstatus, false, 0, true);
        info.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityerror, false, 0, true);
        info.addEventListener(Event.INIT, initialize, false, 0, true);
        info.addEventListener(Event.COMPLETE, complete, false, 0, true);
        try {
            var context:LoaderContext = new LoaderContext();
            context.applicationDomain = ApplicationDomain.currentDomain;
            context.securityDomain = SecurityDomain.currentDomain;
            loader.load(new URLRequest(file), context);
        } catch (err:Error) {
            trace(err.message);
        }
    }
    public function unload():void {
        loader.unload();
    }
    private function progress(evt:ProgressEvent):void {
        dispatchEvent(evt);
    }
    private function ioerror(evt:IOErrorEvent):void {
        loader.unload();
        dispatchEvent(new Event(FontLoader.IO_ERROR));
    }
    private function httpstatus(evt:HTTPStatusEvent):void {
        dispatchEvent(new Event(FontLoader.HTTP_STATUS));
    }
    private function securityerror(evt:SecurityErrorEvent):void {
        dispatchEvent(new Event(FontLoader.SECURITY_ERROR));
    }
    private function initialize(evt:Event):void {
        dispatchEvent(new Event(FontLoader.INIT));
    }
    private function complete(evt:Event):void {
        info.removeEventListener(IOErrorEvent.IO_ERROR, ioerror);
        info.removeEventListener(HTTPStatusEvent.HTTP_STATUS, httpstatus);
        info.removeEventListener(SecurityErrorEvent.SECURITY_ERROR, securityerror);
        info.removeEventListener(Event.INIT, initialize);
        info.removeEventListener(Event.COMPLETE, complete);
        var FontClass:Class = Class(ApplicationDomain.currentDomain.getDefinition(className));
        if (!embeded) {
            Font.registerFont(FontClass);
            _font = Font(new FontClass());
        } else {
            var document:Object = new FontClass();
            _font = document.font;
        }
        _fontName = _font.fontName;
        dispatchEvent(new Event(FontLoader.COMPLETE));
    }
    public function get className():String {
        return _className;
    }
    public function get font():Font {
        return _font;
    }
    public function get fontName():String {
        return _fontName;
    }

}


//////////////////////////////////////////////////
// Labelクラス
//////////////////////////////////////////////////

import flash.display.Sprite;
import flash.text.TextField;
import flash.text.TextFieldType;
import flash.text.TextFieldAutoSize;
import flash.text.AntiAliasType;
import flash.text.TextFormat;
import flash.text.TextFormatAlign;

class Label extends Sprite {
    private var txt:TextField;
    private static var fontType:String = "Myriad Pro Semibold";
    private var _width:uint = 20;
    private var _height:uint = 20;
    private var size:uint = 12;
    public static const LEFT:String = TextFormatAlign.LEFT;
    public static const CENTER:String = TextFormatAlign.CENTER;
    public static const RIGHT:String = TextFormatAlign.RIGHT;

    public function Label(w:uint, h:uint, s:uint = 12, align:String = LEFT) {
        _width = w;
        _height = h;
        size = s;
        draw(align);
    }

    private function draw(align:String):void {
        txt = new TextField();
        addChild(txt);
        txt.width = _width;
        txt.height = _height;
        txt.autoSize = align;
        txt.type = TextFieldType.DYNAMIC;
        txt.selectable = false;
        txt.embedFonts = true;
        txt.antiAliasType = AntiAliasType.ADVANCED;
        var tf:TextFormat = new TextFormat();
        tf.font = fontType;
        tf.size = size;
        tf.align = align;
        txt.defaultTextFormat = tf;
        textColor = 0x000000;
    }
    public function set text(param:String):void {
        txt.text = param;
    }
    public function set textColor(param:uint):void {
        txt.textColor = param;
    }

}


//////////////////////////////////////////////////
// SoundEffectクラス
//////////////////////////////////////////////////

import flash.events.EventDispatcher;
import flash.events.Event;
import flash.events.ProgressEvent;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.media.SoundTransform;
import flash.net.URLRequest;
import flash.media.SoundLoaderContext;

class SoundEffect extends EventDispatcher {
    public var id:String;
    private var sound:Sound;
    private var channel:SoundChannel;
    private var level:Number;
    private var volume:Number = 1;
    private var looping:Boolean = false;
    public var initialized:Boolean = false;
    public var playing:Boolean = false;

    public function SoundEffect() {
    }

    public function init(Snd:Class):void {
        sound = new Snd();
    }
    public function load(filePath:String):void {
        sound = new Sound();
        sound.addEventListener(ProgressEvent.PROGRESS, progress, false, 0, true);
        sound.addEventListener(Event.COMPLETE, initialize, false, 0, true);
        try {
            sound.load(new URLRequest(filePath), new SoundLoaderContext(10, true));
        } catch (err:Error) {
            trace(err.message);
        }
    }
    private function progress(evt:ProgressEvent):void {
        dispatchEvent(evt);
    }
    private function initialize(evt:Event):void {
        initialized = true;
        channel = sound.play();
        channel.stop();
        dispatchEvent(evt);
    }
    public function play(lv:Number, loop:Boolean = false):void {
        playing = true;
        if (channel) channel.stop();
        level = lv;
        looping = loop;
        channel = sound.play();
        var transform:SoundTransform = channel.soundTransform;
        transform.volume = level*volume;
        channel.soundTransform = transform;
        if (looping) {
            channel.addEventListener(Event.SOUND_COMPLETE, complete, false, 0, true);
        }
    }
    public function stop():void {
        playing = false;
        if (channel) {
            channel.stop();
            channel.removeEventListener(Event.SOUND_COMPLETE, complete);
        }
    }
    public function setVolume(v:Number):void {
        volume = v;
        if (channel) {
            var transform:SoundTransform = channel.soundTransform;
            transform.volume = level*volume;
            channel.soundTransform = transform;
        }
    }
    private function complete(evt:Event):void {
        channel.removeEventListener(Event.SOUND_COMPLETE, complete);
        if (looping) {
            channel = sound.play(0);
            channel.addEventListener(Event.SOUND_COMPLETE, complete, false, 0, true);
            var transform:SoundTransform = channel.soundTransform;
            transform.volume = level*volume;
            channel.soundTransform = transform;
        } else {
            playing = false;
        }
    }

}