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

目が光るパンダDJ

////////////////////////////////////////////////////////////////////////////////
// 目が光るパンダDJ
//
// gaina's soundtest7 - E.R.O [http://wonderfl.net/c/2VSs]
// 目が光るひよこちゃんDJ [http://wonderfl.net/c/fzpTw]
////////////////////////////////////////////////////////////////////////////////
Get Adobe Flash player
by ProjectNya 10 Dec 2010
/**
 * Copyright ProjectNya ( http://wonderfl.net/user/ProjectNya )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/sFjs
 */

////////////////////////////////////////////////////////////////////////////////
// 目が光るパンダDJ
//
// gaina's soundtest7 - E.R.O [http://wonderfl.net/c/2VSs]
// 目が光るひよこちゃんDJ [http://wonderfl.net/c/fzpTw]
////////////////////////////////////////////////////////////////////////////////

package {

    import flash.display.Sprite;
    import flash.display.MovieClip;
    import flash.display.Loader;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.net.URLRequest;
    import flash.system.Security;
    import flash.system.LoaderContext;
    import flash.display.Shape;
    import flash.geom.Matrix;
    import flash.display.GradientType;
    import flash.display.BlendMode;
    import flash.media.Sound;
    import flash.media.SoundChannel;
    import flash.media.SoundLoaderContext;
    import flash.media.SoundMixer;
    import flash.utils.ByteArray;

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

    public class Main extends Sprite {
        private var loader:Loader;
        private static var pandaPath:String = "http://www.project-nya.jp/images/flash/panda2d.swf";
        private var Panda:Class;
        private var panda:MovieClip;
        private var disc:Sprite;
        private var eyes:Array;
        private static var basePath:String = "http://assets.wonderfl.net/images/related_images/";
        private static var lightPath:String = "4/40/400b/400b814a16b90c750e41bcd00890213280cd1be7";
        private var initialized:uint = 0;
        private var sound:Sound;
        private static var soundPath:String = "http://www.takasumi-nagai.com/soundfiles/sound001.mp3";

        public function Main() {
            //Wonderfl.disable_capture();
            Wonderfl.capture_delay(11);
            init();
        }

        private function init():void {
            draw();
            Security.allowDomain("www.project-nya.jp");
            loader = new Loader();
            loader.contentLoaderInfo.addEventListener(Event.COMPLETE, complete, false, 0, true);
            loader.load(new URLRequest(pandaPath), new LoaderContext(true));
            sound = new Sound();
            sound.addEventListener(Event.COMPLETE, prepare, false, 0, true);
            sound.load(new URLRequest(soundPath), new SoundLoaderContext(10, true));
        }
        private function complete(evt:Event):void {
            loader.removeEventListener(Event.COMPLETE, complete);
            var content:MovieClip = MovieClip(evt.target.content);
            //Pandaクラス
            Panda = MovieClip(content.panda).constructor;
            setup();
            loader = null;
        }
        private function setup():void {
            //Pandaインスタンス
            panda = new Panda();
            addChild(panda);
            panda.x = 232;
            panda.y = 400;
            panda.scale = 5;
            addChild(disc);
            disc.x = 232;
            disc.y = 440;
            eyes = new Array();
            createEyeLight(182, 222);
            createEyeLight(282, 222);
        }
        private function createEyeLight(ex:uint, ey:uint):void {
            var eye:Sprite = new Sprite();
            addChild(eye);
            eye.x = ex;
            eye.y = ey;
            eyes.push(eye);
            eye.blendMode = BlendMode.ADD;
            var loader:Loader = new Loader();
            loader.contentLoaderInfo.addEventListener(Event.COMPLETE, loaded, false, 0, true);
            eye.addChild(loader);
            loader.x = -128;
            loader.y = -128;
            loader.load(new URLRequest(basePath + lightPath), new LoaderContext(true));
            eye.scaleX = eye.scaleY = 0;
        }
        private function loaded(evt:Event):void {
            evt.target.removeEventListener(Event.COMPLETE, loaded);
            initialized ++;
            if (initialized > 2) start();
        }
        private function prepare(evt:Event):void {
            evt.target.removeEventListener(Event.COMPLETE, prepare);
            initialized ++;
            if (initialized > 2) start();
        }
        private function start():void {
            var channel:SoundChannel = sound.play(0, 5);
            addEventListener(Event.ENTER_FRAME, update, false, 0, true);
        }
        private function update(evt:Event):void {
            var bytes:ByteArray = new ByteArray();
            SoundMixer.computeSpectrum(bytes, false, 1);
            for (var n:uint = 0; n < 2; n++) {
                var eye:Sprite = eyes[n];
                for (var t:uint = 0; t < 256; t++) {
                    var rf:Number = bytes.readFloat();
                    eye.scaleX = eye.scaleY = rf*5;
                }
            }
        }
        /////////////////////////////////////////////
        //背景
        /////////////////////////////////////////////
        private function draw():void {
            drawSky();
            drawGround();
            drawDisc();
            var label:Label = new Label(400, 16);
            label.x = 232 - 200;
            label.y = 10;
            label.text = "部屋を明るくしてなるべく画面からはなれて見ましょう";
            label.textColor = 0xFFFFFF;
            label.alpha = 0.6;
            addChild(label);
        }
        private function drawSky():void {
            var matrix:Matrix = new Matrix();
            matrix.createGradientBox(465, 350, 0.5*Math.PI, 0, 0);
            graphics.beginGradientFill(GradientType.LINEAR, [0x3F68AB, 0x77B2EE], [1, 1], [0, 255], matrix);
            graphics.drawRect(0, 0, 465, 350);
            graphics.endFill();
        }
        private function drawGround():void {
            var matrix:Matrix = new Matrix();
            matrix.createGradientBox(465, 150, 0.5*Math.PI, 0, 350);
            graphics.beginGradientFill(GradientType.LINEAR, [0x99CC33, 0x7EB133], [1, 1], [0, 255], matrix);
            graphics.drawRect(0, 350, 465, 150);
            graphics.endFill();
        }
        private function drawDisc():void {
            disc = new Sprite();
            disc.graphics.beginFill(0x666666);
            disc.graphics.moveTo(-110, -100);
            disc.graphics.lineTo(110, -100);
            disc.graphics.lineTo(150, -70);
            disc.graphics.lineTo(-150, -70);
            disc.graphics.endFill();
            disc.graphics.beginFill(0x333333);
            disc.graphics.drawRect(-150, -70, 300, 70);
            disc.graphics.endFill();
            disc.graphics.beginFill(0x000000);
            disc.graphics.drawEllipse(-90, -95, 80, 20);
            disc.graphics.drawEllipse(-58, -87, 16, 4);
            disc.graphics.endFill();
            disc.graphics.beginFill(0x000000);
            disc.graphics.drawEllipse(10, -95, 80, 20);
            disc.graphics.drawEllipse(42, -87, 16, 4);
            disc.graphics.endFill();
        }

    }

}


//////////////////////////////////////////////////
// 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 = "Arial";
    private var txtWidth:uint;
    private var fontSize:uint;

    public function Label(w:uint, s:uint) {
        txtWidth = w;
        fontSize = s;
        draw();
    }

    private function draw():void {
        txt = new TextField();
        txt.width = txtWidth;
        addChild(txt);
        txt.autoSize = TextFieldAutoSize.CENTER;
        txt.type = TextFieldType.DYNAMIC;
        txt.selectable = false;
        //txt.embedFonts = true;
        //txt.antiAliasType = AntiAliasType.ADVANCED;
        var tf:TextFormat = new TextFormat();
        tf.font = fontType;
        tf.size = fontSize;
        tf.align = TextFormatAlign.CENTER;
        txt.defaultTextFormat = tf;
    }
    public function set text(param:String):void {
        txt.text = param;
    }
    public function set textColor(param:uint):void {
        txt.textColor = param;
    }

}