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

soundtest024

sound by AlainMikuni
Get Adobe Flash player
by gaina 15 Apr 2011
/**
 * Copyright gaina ( http://wonderfl.net/user/gaina )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/he6r
 */

package 
{
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.media.Sound;
    import flash.media.SoundChannel;
    import flash.media.SoundLoaderContext;
    import flash.media.SoundMixer;
    import flash.media.SoundTransform;
    import flash.net.URLRequest;
    import flash.system.Security;
    import flash.utils.ByteArray;
    
    [SWF(width = 465, height = 465, backgroundColor = 0 )]
    public class Main extends Sprite
    {
        private var snd:Sound;
        private var sndChannel:SoundChannel;
        
        private var _container:Sprite;
        private var _len:Number;
        private var _array:Array = [];
        
        public function Main():void 
        {
            this.graphics.beginFill(0);
            this.graphics.drawRect(0, 0, 465, 465);
            this.graphics.endFill();
            
            Security.allowDomain("takasumi-nagai.com");
            playSound("http://www.takasumi-nagai.com/soundfiles/sound003.mp3");
        }
        
        private function playSound(sndUrl:String):void
        {
            snd = new Sound();
            var context:SoundLoaderContext = new SoundLoaderContext(10,true);
            var req:URLRequest = new URLRequest(sndUrl);
            snd.load(req, context);
            snd.addEventListener(Event.COMPLETE, onComp);
        }
        
        private function onComp(e:Event):void 
        {
            sndChannel=new SoundChannel();
            sndChannel = snd.play(0, 10, new SoundTransform(0.3, 0));
            
            for (var i:int = 0; i < 128; i++)
            {
                var r:RoundRect = new RoundRect();
                r.x = Math.random() * 465;
                r.y = Math.random() * 465;
                addChild(r);
                _array.push(r);
            }
            addEventListener(Event.ENTER_FRAME, loop);
        }
        
        private function loop(event:Event):void 
        {
            var bytes:ByteArray = new ByteArray();
            SoundMixer.computeSpectrum(bytes, false, 0);
            bytes.position = 0;
            
            for (var i:int = 0; i < _array.length; i++)
            {
                var r:RoundRect = _array[i] as RoundRect;
                var _arr:Array = [];
                for (var b:int = 0; b < 4; b++)
                {
                    _arr.push(bytes.readFloat() * 15);
                }
                r.step(_arr);
                if(r.x < 0) r.x = stage.stageWidth;
                if(r.x > stage.stageWidth) r.x = 0;
                if(r.y < 0) r.y = stage.stageHeight;
                if(r.y > stage.stageHeight) r.y = 0;
            }
        }
    }
}

import flash.display.LineScaleMode;
import flash.display.Sprite;
import flash.geom.Point;

class RoundRect extends Sprite {
    
    public var _p1:Point;
    public var _p2:Point;
    public var _p3:Point;
    public var _p4:Point;
    
    private var _sp:Sprite;
    private var _len:int;
    
    public function RoundRect(len:int = 10)
    {
        _len = len;
        
        _p1 = new Point( -_len / 2, -_len / 2);
        _p2 = new Point(_len / 2, -_len / 2);
        _p3 = new Point(_len / 2, _len / 2);
        _p4 = new Point( -_len / 2, _len / 2);
        
        _sp = new Sprite();
        _sp.graphics.beginFill(0xFFFFFF);
        _sp.graphics.lineStyle(1, 0, 1, false, LineScaleMode.NONE);
        _sp.graphics.moveTo(_p1.x, _p1.y);
        _sp.graphics.lineTo(_p2.x, _p2.y);
        _sp.graphics.lineTo(_p3.x, _p3.y);
        _sp.graphics.lineTo(_p4.x, _p4.y);
        _sp.graphics.lineTo(_p1.x, _p1.y);
        _sp.graphics.endFill();
        
        _sp.blendMode = "invert";
        
        addChild(_sp);
    }
    
    public function step(_arr:Array):void
    {
        if (_arr == null || _arr.length != 4) return;
        
        var b1:Number = _arr[0];
        var b2:Number = _arr[1];
        var b3:Number = _arr[2];
        var b4:Number = _arr[3];
        
        _sp.graphics.clear();
        //_sp.graphics.beginFill(Math.floor(b1 * 10000));
        _sp.graphics.beginFill(0);
        _sp.graphics.lineStyle(1, 0, 1, false, LineScaleMode.NONE);
        _sp.graphics.moveTo(_p1.x + b1, _p1.y + b1);
        _sp.graphics.lineTo(_p2.x + b2, _p2.y + b2);
        _sp.graphics.lineTo(_p3.x + b3, _p3.y + b3);
        _sp.graphics.lineTo(_p4.x + b4, _p4.y + b4);
        _sp.graphics.lineTo(_p1.x + b1, _p1.y + b1);
        _sp.graphics.endFill();
        
        _sp.scaleX = b1 + b2;
        _sp.scaleY = b3 + b4;
        
        this.rotation += b1 + b2 + b3 + b4;
        this.x += b1 + b2;
        this.y += b3 + b4;
    }
}