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: soundtest17

Get Adobe Flash player
by aobyrne 29 May 2012
/**
 * Copyright aobyrne ( http://wonderfl.net/user/aobyrne )
 * MIT License ( http://www.opensource.org/licenses/mit-license.php )
 * Downloaded from: http://wonderfl.net/c/14rl
 */

package 
{
    import com.bit101.components.CheckBox;
    import com.bit101.components.HUISlider;
    import com.bit101.components.Label;
    import com.bit101.components.VBox;
    import flash.display.Graphics;
    import flash.display.Shape;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.media.SoundMixer;
    import flash.text.TextField;
    import flash.utils.ByteArray;
    
    /**
     * ...
     * @author gaina
     */
    
    [SWF(width="465",height="465")]
    public class Soundtest17 extends Sprite 
    {
        private var _sound:SoundPlay;
        private var _arr:Array;
        private var hasDrawn:Boolean;
        private var stretchLength:SCConfHUISLider;
        private var sh:Shape;
        
        public function Soundtest17():void 
        {
            if (stage) init();
            else addEventListener(Event.ADDED_TO_STAGE, init);
        }
        
        private function init(e:Event = null):void 
        {
            removeEventListener(Event.ADDED_TO_STAGE, init);
            // entry point
            
            _sound = new SoundPlay("http://www.takasumi-nagai.com/","soundfiles/sound005.mp3");
            _sound.load();
            _sound.addEventListener(Event.COMPLETE, Completed);
            
            _arr = SquereArray();
            
            var vbox:VBox = new VBox(this, 150, 0);
            
            stretchLength = new SCConfHUISLider(vbox, 0, 20, 0, 'stretch');
                    sh = addChild(new Shape) as Shape;
                    setChildIndex(sh, 0);
            new CheckBox(this, 120, 0,'',function ():void{sh.visible=!sh.visible});
        }
        
        private function Completed(e:Event):void 
        {
            _sound.play();
            addEventListener(Event.ENTER_FRAME, loop);
        }
        
        private function loop(e:Event):void 
        {
            var factor:Number =  0.75;
            var _byte:ByteArray = new ByteArray();
            SoundMixer.computeSpectrum(_byte, false, stretchLength.value);
            
            for (var i:int = 0; i < 16; i++) {
                var ini:int = _byte.position = i * 32;
                
                //var _sp:Sprite = _arr[i][0] as Sprite;
                var amount:int = 4;
                //4 per float, 4 floats per coordinate and 2 coordinates per loop
                var bytesReadPerLoop:int = 4 * 4 * 2;
                var bytesRead:int = bytesReadPerLoop * amount;
                for (var j:int = 0; j < amount; j++) {
                    var _s:Sprite = _arr[i][1][j] as Sprite;
                    _s.x = 0;
                    _s.y = 0;
                    
                    _s.x =  (_byte.readFloat() + _byte.readFloat() + _byte.readFloat() + _byte.readFloat()) * 10 * Math.cos(Number(_s.name));
                    _s.y =  (_byte.readFloat() + _byte.readFloat() + _byte.readFloat() + _byte.readFloat()) * 10 * Math.sin(Number(_s.name));
                }
                if (!hasDrawn) {
                    var lineSize:Number = 110;
                    var g:Graphics = sh.graphics;
                    g.lineStyle(0);
                    g.beginFill(0xffffff * Math.random(), 0.62);
                    var xx:Number = 10 + 50 * (i % 2);
                    var yy:Number = ini * factor;
                    var xxgap:Number = 4 * Math.random() - 8;
                    g.drawRect(xx+xxgap, yy+2, 20 + Math.random() * 10-2*xxgap, bytesRead * factor-4);
                    var textField:TextField = new TextField;
                    textField.text = i.toString();
                    textField.x = xx;
                    textField.y = yy;
                    textField.selectable = false;
                    addChild(textField);
                    g.lineStyle(2);
                    g.endFill();
                    g.moveTo(0, yy);
                    g.lineTo(lineSize, yy);
                    trace( "_byte.position : " + _byte.position );
                    trace( "range : " + (_byte.position -ini));
                    var number:Number = 4 * 8 * 4;
                    //var number3:Number = (608 - 512)/16;
                    trace('-------------------------------');
                    var number1:Number = 16 * 32;
                    g.lineStyle(NaN)
                    g.beginFill(0);
                    g.drawRect(lineSize, 0, 10, 512 * factor);
                    g.endFill();
                    trace( "number1 : " + number1 );
                }
            }
            hasDrawn = true;

            //removeEventListener(Event.ENTER_FRAME, loop);
        }
        
        private function SquereArray():Array
        {
            
            var arr:Array = [];
            
            for ( var i:int = 0; i < 16; i++)
            {
                var _array:Array = [];
                var _sp:Sprite = new Sprite();
                _sp.graphics.lineStyle(1, 0);
                _sp.graphics.drawRoundRect( -55, -55, 110, 110, 0);
                _sp.graphics.endFill();
                
                _sp.x = 60 + 115 * (i % 4);
                _sp.y = 60 + 115 * Math.floor(i / 4);
                
                addChild(_sp);
                _array.push(_sp);
                
                var array:Array = [];
                
                for (var j:int = 0; j < 4; j++)
                {
                    var _child:Sprite = new Sprite();
                    _child.graphics.lineStyle(1, 0);
                    _child.graphics.drawCircle(0, 0, 25);
                    _child.graphics.endFill();
                    _child.name = Number(Math.random() * 2 * Math.PI).toString();
                    _sp.addChild(_child);
                    
                    array.push(_child);
                }
                _array.push(array);
                
                arr.push(_array);
                
                var _label:Label = new Label(_sp, -4, 35, (i + 1).toString());
            }
            
            return arr;
        }
        
    }
    
}
import com.bit101.components.Component;
import flash.events.Event;
import flash.events.EventDispatcher;
import flash.events.IOErrorEvent;
import flash.events.ProgressEvent;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.media.SoundLoaderContext;
import flash.media.SoundTransform;
import flash.net.URLRequest;
import flash.system.Security;


class SoundPlay extends EventDispatcher
{
    private var _sound:Sound;
    private var _channel:SoundChannel;
    private var _url:String;
    
    public function SoundPlay(_domain:String , url:String)
    {
        Security.allowDomain(_domain);        
        
        _url = _domain+url;
        _sound = new Sound();
    }
    
    public function load():void
    {
        var _context:SoundLoaderContext = new SoundLoaderContext(1000, true);
        _sound.load(new URLRequest(_url), _context);
        _sound.addEventListener(ProgressEvent.PROGRESS, onProgress);
        _sound.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
        _sound.addEventListener(Event.COMPLETE, SoundLoaded);
    }
    
    public function play():void
    {
        _sound.play(0, 100, new SoundTransform(1, 0));
    }
    
    private function onIOError(e:IOErrorEvent):void 
    {
        dispatchEvent(new IOErrorEvent(IOErrorEvent.IO_ERROR));
    }
    
    private function onProgress(e:ProgressEvent):void 
    {
        dispatchEvent(new ProgressEvent(ProgressEvent.PROGRESS));
    }
    
    private function SoundLoaded(e:Event):void 
    {
        _sound.removeEventListener(IOErrorEvent.IO_ERROR, onIOError);
        _sound.removeEventListener(ProgressEvent.PROGRESS, onProgress);
        _sound.removeEventListener(Event.COMPLETE, SoundLoaded);
        dispatchEvent(new Event(Event.COMPLETE));
    }
}
import com.bit101.components.HUISlider;
class SCConfHUISLider extends HUISlider
{
    public function SCConfHUISLider(box:Component,min:Number,max:Number,value:Number,label:String) 
    {
        super(box, 0, 0, label);
        minimum = min;
        maximum = max;
        this.value = value;
        this.label = label;
    }
}