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

[test] - soundtest12

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

package 
{
    import flash.display.Bitmap;
    import flash.display.BitmapData;
    import flash.display.Sprite;
    import flash.events.Event;
    import flash.events.NetStatusEvent;
    import flash.geom.ColorTransform;
    import flash.geom.Matrix;
    import flash.media.SoundMixer;
    import flash.media.Video;
    import flash.net.NetConnection;
    import flash.net.NetStream;
    import flash.utils.ByteArray;
    
    /**
     * ...
     * @author gaina
     * sound by AlainMikuni
     */
     
    public class Main extends Sprite 
    {
        private var w:Number;
        private var h:Number;
        
        private const WIDTH:int = 465;
        private const HEIGHT:int = 465;
        
        private var _path:String = "http://www.takasumi-nagai.com/videofiles/";
        private var _url:String = "20100912.f4v";
        private var _nc:NetConnection;
        private var _video:Video;
        private var _ns:NetStream;
        
        private var _bmpd:BitmapData;
        private var _bitmap:Bitmap;
        
        private var _red:Number = 1;
        private var _blue:Number = 1;
        private var _green:Number = 1;
        
        public function Main():void 
        {
            if (stage) init();
            else addEventListener(Event.ADDED_TO_STAGE, init);
        }
        
        private function init(e:Event = null):void 
        {
            removeEventListener(Event.ADDED_TO_STAGE, init);
            
            var _sound:PlaySound = new PlaySound("http://www.takasumi-nagai.com/soundfiles/sound006.mp3");
            
            w = stage.stageWidth;
            h = stage.stageHeight;
            
            _video = new Video(w, h);
            
            _bmpd = new BitmapData(w, h, false);
            _bitmap = new Bitmap(_bmpd);
            addChild(_bitmap);
            
            _nc = new NetConnection();
            _nc.addEventListener(NetStatusEvent.NET_STATUS, ConnectCheck);
            _nc.connect(null);
        }
        
        private function ConnectCheck(e:NetStatusEvent):void 
        {
            if (e.info.code == "NetConnection.Connect.Success")
            {
                _ns = new NetStream(_nc);
                _ns.client = { };
                _video.attachNetStream(_ns);
                _ns.checkPolicyFile = true;
                _ns.play(_path + _url);
                _ns.addEventListener(NetStatusEvent.NET_STATUS, onCompleteEvent);
                
                addEventListener(Event.ENTER_FRAME, loop);
            }
        }
        
        private function loop(e:Event):void 
        {
            _bmpd.draw(_video, new Matrix(1, 0, 0, 1, 0, 0), new ColorTransform(_red, _blue, _green), null, null, true);
            
            var _byte:ByteArray = new ByteArray();
            SoundMixer.computeSpectrum(_byte, true);
            for (var i:int = 0; i < 144; i++)
            {
                var data:Number = _byte.readFloat();
                if (0 <= i < 16) {
                    if (data > 0.9) {
                        _red += 0.02;
                        if (_red > 1) _red = 0;
                    }
                }
                if (64 <= i < 80) {
                    if (data > 0.8) {
                        _blue += 0.04;
                        if(_blue > 1)_blue = 0;
                    }
                }
                if (128 <= i < 144 ) {
                    if (data > 0.7) {
                        _green += 0.1;
                        if (_green > 1)_green = 0;
                    }
                }
            }
        }
        
        private function onCompleteEvent(e:NetStatusEvent):void 
        {
            if (e.info.code == "NetStream.Play.Stop")
            {
                _ns.play(_path + _url);
            }
        }
    }
}

import flash.events.Event;
import flash.media.Sound;
import flash.media.SoundLoaderContext;
import flash.media.SoundTransform;
import flash.net.URLRequest;

class PlaySound
{
    private var sound:Sound;

        public function PlaySound(url:String)
        {
            sound = new Sound();
            var _context:SoundLoaderContext = new SoundLoaderContext(1000, true);
            sound.addEventListener(Event.COMPLETE, SoundLoadeComplete);
            sound.load(new URLRequest(url), _context);
        }
        
        private function SoundLoadeComplete(e:Event):void 
        {
            sound.play(0, 10, new SoundTransform(0.5, 0));
        }
}