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

Bomb (1)

Get Adobe Flash player
by ProjectNya 16 Oct 2010
    Embed
/**
 * Copyright ProjectNya ( http://wonderfl.net/user/ProjectNya )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/fL1o
 */

////////////////////////////////////////////////////////////////////////////////
// Bomb (1)
////////////////////////////////////////////////////////////////////////////////

package {

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

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

    public class Main extends Sprite {
        private var bomb:Bomb;
        private static var radius:uint = 120;

        public function Main() {
            init();
        }

        private function init():void {
            bomb = new Bomb(radius);
            addChild(bomb);
            bomb.x = 232;
            bomb.y = 272;
            bomb.buttonMode = true;
            bomb.addEventListener(MouseEvent.MOUSE_OVER, rollOver, false, 0, true);
            bomb.addEventListener(MouseEvent.MOUSE_OUT, rollOut, false, 0, true);
        }
        private function rollOver(evt:MouseEvent):void {
            bomb.start();
        }
        private function rollOut(evt:MouseEvent):void {
            bomb.stop();
        }

    }

}


//////////////////////////////////////////////////
// Bombクラス
//////////////////////////////////////////////////

import flash.display.Sprite;
import flash.display.Shape;
import flash.events.Event;
import flash.filters.DropShadowFilter;
import flash.filters.GlowFilter;
import flash.geom.Matrix;
import flash.display.GradientType;
import flash.display.SpreadMethod;
import flash.display.InterpolationMethod;
import flash.display.BlendMode;

class Bomb extends Sprite {
    private var radius:uint;
    private var color:uint = 0x000000;
    private var bomb:Sprite;
    private var string:Shape;
    private var fire:Shape;
    private var base:Shape;
    private var shadow:Shape;
    private var light:Shape;
    private var reflection:Shape;
    private var shade:Shape;
    private static var bColor:uint = 0xFFFFFF;
    private static var sColor:uint = 0x000000;
    private static var fColor:uint = 0xFF0000;
    private var sx:Number = 0;
    private var sy:Number = 0;
    private var fx:Number = 0;
    private var fy:Number = 0;

    public function Bomb(r:uint) {
        radius = r;
        draw();
        mouseChildren = false;
    }

    private function draw():void {
        sx = radius*Math.cos(-100*Math.PI/180);
        sy = radius*Math.sin(-100*Math.PI/180);
        fx = sx-radius*0.3;
        fy = sy-radius*0.5;
        //
        shade = new Shape();
        addChild(shade);
        shade.y = radius;
        bomb = new Sprite();
        addChild(bomb);
        string = new Shape();
        bomb.addChild(string);
        fire = new Shape();
        bomb.addChild(fire);
        base = new Shape();
        bomb.addChild(base);
        shadow = new Shape();
        bomb.addChild(shadow);
        light = new Shape();
        bomb.addChild(light);
        reflection = new Shape();
        bomb.addChild(reflection);
        createBase();
        createShade();
        createShadow();
        createLight();
        createReflect();
        createString();
        createFire();
        fire.visible = false;
    }
    public function start():void {
        fire.visible = true;
        addEventListener(Event.ENTER_FRAME, update, false, 0, true);
    }
    public function stop():void {
        fire.visible = false;
        removeEventListener(Event.ENTER_FRAME, update);
    }
    private function update(evt:Event):void {
        fire.x = fx + (Math.random()-0.5)*2;
        fire.y = fy + (Math.random()-0.5)*2;
    }
    private function createBase():void {
        base.graphics.clear();
        base.graphics.beginFill(color, 0.8);
        base.graphics.drawCircle(0, 0, radius);
        base.graphics.endFill();
    }
    private function createString():void {
        string.graphics.lineStyle(10, color, 0.8);
        string.graphics.moveTo(sx, sy);
        string.graphics.curveTo(sx-radius*0.2, sy-radius*0.1, sx-radius*0.1, sy-radius*0.25);
        string.graphics.curveTo(sx, sy-radius*0.4, fx, fy);
    }
    private function createFire():void {
        var colors:Array = [fColor, fColor, fColor];
        var alphas:Array = [1, 1, 0];
        var ratios:Array = [0, 63, 255];
        var matrix:Matrix = new Matrix();
        matrix.createGradientBox(radius*0.32, radius*0.32, 0, -radius*0.16, -radius*0.16);
        fire.graphics.beginGradientFill(GradientType.RADIAL, colors, alphas, ratios, matrix, SpreadMethod.PAD, InterpolationMethod.RGB, 0);
        fire.graphics.drawCircle(0, 0, radius*0.16);
        fire.graphics.endFill();
        fire.x = fx;
        fire.y = fy;
    }
    private function createShadow():void {
        var colors:Array = [sColor, sColor, sColor];
        var alphas:Array = [0, 0.2, 0.3];
        var ratios:Array = [0, 191, 255];
        var matrix:Matrix = new Matrix();
        matrix.createGradientBox(radius*3.2, radius*3.2, 0, -radius*2, -radius*2);
        shadow.graphics.beginGradientFill(GradientType.RADIAL, colors, alphas, ratios, matrix, SpreadMethod.PAD, InterpolationMethod.RGB, 0);
        shadow.graphics.drawCircle(0, 0, radius);
        shadow.graphics.endFill();
        shadow.blendMode = BlendMode.HARDLIGHT;
    }
    private function createLight():void {
        var colors:Array = [bColor, bColor, bColor];
        var alphas:Array = [1, 0.2, 0];
        var ratios:Array = [0, 191, 255];
        var matrix:Matrix = new Matrix();
        matrix.createGradientBox(radius*3.2, radius*3.2, 0, -radius*2, -radius*2);
        light.graphics.beginGradientFill(GradientType.RADIAL, colors, alphas, ratios, matrix, SpreadMethod.PAD, InterpolationMethod.RGB, 0);
        light.graphics.drawCircle(0, 0, radius);
        light.graphics.endFill();
        light.blendMode = BlendMode.OVERLAY;
    }
    private function createReflect():void {
        var colors:Array = [bColor, bColor];
        var alphas:Array = [0.7, 0];
        var ratios:Array = [0, 191];
        var matrix:Matrix = new Matrix();
        var w:Number = radius*1.44;
        var h:Number = radius*1.35;
        var yOffset:Number = radius*0.95;
        matrix.createGradientBox(w, h, 0.5*Math.PI, -w*0.5, -yOffset);
        reflection.graphics.beginGradientFill(GradientType.LINEAR, colors, alphas, ratios, matrix, SpreadMethod.PAD, InterpolationMethod.RGB, 0);
        reflection.graphics.drawEllipse(-w*0.5, -yOffset, w, h);
        reflection.graphics.endFill();
    }
    private function createShade():void {
        shade.graphics.beginFill(sColor, 0.6);
        shade.graphics.drawEllipse(-radius*0.75, -radius*0.1775, radius*1.5, radius*0.375);
        shade.graphics.endFill();
        var shadow:DropShadowFilter = new DropShadowFilter(0, 90, sColor, 0.5, radius*0.15, radius*0.15, 1, 3, false, false, true);
        shade.filters = [shadow];
    }

}