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

SoundMixerでちょっと遊んでみる3

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

package  {
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.MouseEvent;
    import flash.events.TimerEvent;
    import flash.filters.BlurFilter;
    import flash.utils.Timer;
    import flash.utils.ByteArray;
    import flash.media.SoundMixer;
    import flash.system.Security;
    import flash.filters.GlowFilter;
    import flash.filters.BevelFilter;
    
    [SWF(width="465", height="465", backgroundColor="#000000", frameRate="30")]
    
    public class Main extends Sprite{
        
        private var _container:Sprite;
        private var _list:Array = new Array();
        private var _colorList:Array = new Array();
        private var _xCount:int;;
        private var _yCount:int;;
        private var _size:Number = 20;
        private var _xRepeat:int = (stage.stageWidth+_size)/_size;
        private var _yRepeat:int = (stage.stageHeight+_size)/_size;
        private var _repeat:int = _xRepeat*_yRepeat;
        //
        private var _timer:Timer;
        //       
        private var _waveBytes:ByteArray = new ByteArray();
        private var _sound:SoundPlayStop;
        //
        private static const CHENGE_NUM:int = 0x0FFF00;
        private var _color:int = 0xFF0000;
        private var _density:int = 150;
        private var _waveWidth:Number = 0.1;
        
        private var _glow:GlowFilter
        private var _bevel:BevelFilter
        
        public function Main() {
            Security.loadPolicyFile("http://www.digifie.jp/crossdomain.xml");
            //
            var base:Sprite = new Base(0x000000, stage.stageWidth, stage.stageHeight)
            addChild(base)
            _container = new Sprite()
            addChild(_container)
            _glow = new GlowFilter(0xFFFFFF,0.7,10,10,2,2,false,false)
            _bevel = new BevelFilter(12,85,0xFFFFFF,0.7,_color,0.5,24,24,1,1,"inner",false)
            
            for(var i:int;i<_repeat;i++){
                _color += CHENGE_NUM;
                _colorList.push(_color)
                if(_xCount>=_xRepeat){
                    _xCount = 0;
                    _yCount+=_size;
                }
                var mc:Sprite = new Rect(_size*.8 ,i, _color);
                _container.addChild(mc);
                _list.push(mc);
                _list[i].x = _size*_xCount;
                _list[i].y = _yCount;
                _list[i].cacheAsBitmap = true;
                _list[i].visible = false;
                //
                _xCount++;
            }
            startDelay();
        }
        
        private function startDelay():void{
            _timer = new Timer(1000,1);
            _timer.addEventListener(TimerEvent.TIMER_COMPLETE, go);
            _timer.start();
        }
        
        private function go(e:TimerEvent):void{
            _timer.removeEventListener(TimerEvent.TIMER_COMPLETE, go);
            _timer=null;
            //
            _sound=new SoundPlayStop()
            _sound.soundStart("http://www.digifie.jp/files/test3.mp3", 100);
            addEventListener(Event.ENTER_FRAME,update);
        }
        
        private function update(e:Event):void{
            var num:Number;
            var flg:Boolean;
            try{
                SoundMixer.computeSpectrum(_waveBytes, true, 0);
                num = Math.floor(_waveBytes.readFloat()*_density);
            }catch(e:Error){
                return;
            }
            //
             for(var i:int=0;i<_list.length;i++){
                _list[i].visible = false;
             }
             for(var j:int=_list.length/2;j<num+_list.length/2;j++){
                flg = Boolean(Math.floor(Math.random()*2.5))
                _bevel.knockout = flg
                var n1:int = Math.floor(Math.random()*_list.length*_waveWidth)
                try{
                     if(!flg){
                         _bevel.shadowColor = 0x000000
                        _list[j+n1].alpha = 0.8 
                     }else{
                        _bevel.shadowColor = _colorList[j+n1]
                        _list[j+n1].alpha = 1 
                     }
                     _list[j+n1].visible = true;
                     _list[j+n1].filters = [_glow, _bevel];
                }catch(e:Error){
                    return;
                }
             }
             for(var k:int=_list.length/2;k>-(num-_list.length/2);k--){
                flg = Boolean(Math.floor(Math.random()*2.5))
                _bevel.knockout = flg
                var n2:int = Math.floor(Math.random()*_list.length*_waveWidth)
                 try{
                     if(!flg){
                         _bevel.shadowColor = 0x000000
                        _list[k-n2].alpha = 0.8 
                     }else{
                        _bevel.shadowColor = _colorList[k-n2]
                        _list[k-n2].alpha = 1 
                     }
                     _list[k-n2].visible = true;
                     _list[k-n2].filters = [_glow, _bevel];
                }catch(e:Error){
                    return;
                }
             }
        }        
    }
}
        
        
import flash.display.Sprite;

class Rect extends Sprite{
    
    private var _size:int;
    private var _num:int;

    
    public function Rect(size:int, n:int, color:int=0xFFFFFF){
        _size = size;
        _num = n;
        graphics.beginFill(color,1);
        graphics.drawCircle(0,0,_size/2);
        graphics.endFill();
    }
    
    public function get num():int{
        return _num;
    }
}


//
import flash.events.Event;
import flash.events.EventDispatcher;
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.media.SoundTransform;
import flash.media.SoundLoaderContext;
import flash.net.URLRequest;
import flash.system.Security;

class SoundPlayStop extends EventDispatcher{
        
    public var my_sc:SoundChannel;
    public var my_sound:Sound;                
    public var _flg:Boolean = true;
    
    public function SoundPlayStop(){
        Security.loadPolicyFile("http://www.digifie.jp/crossdomain.xml");
    }

    public function soundStart(Url:String, ref:uint = 1, vol:Number = 1):void {
        if(_flg){
            var trans:SoundTransform = new SoundTransform(vol,0);
            var context:SoundLoaderContext = new SoundLoaderContext(); 
            context.checkPolicyFile = true;
            //
            if (my_sc != null) {
                my_sc.stop();
                my_sc = null;
            }
            try{
                my_sound = new Sound(new URLRequest(Url),context);
                my_sc = my_sound.play(0,ref);
                my_sc.soundTransform = trans;
            }catch(e:Error){
                trace(e,Url);
            }
        }
    }

    public function soundStop():void {
        if (my_sc != null) {
            my_sc.stop();
            my_sc = null;
            my_sound = null;
        }
    }
}

import flash.display.Sprite
class Base extends Sprite{
    public function Base(color:int,w:int,h:int):void{
        graphics.beginFill(color, 1)
        graphics.drawRect(0,0,w,h)
        graphics.endFill()
    }
}