Common Uses of Byte Arrays : ByteArray : Development Flash / Flex / ActionScript examples


Flash / Flex / ActionScript examples » Development » ByteArray »

 

Common Uses of Byte Arrays


 
package {

    import flash.display.Sprite;
    import flash.utils.ByteArray;
    import flash.media.Sound;
    import flash.media.SoundChannel;
    import flash.media.*;
    import flash.net.URLRequest;
    import flash.events.Event;
    import flash.system.Security;

    public class Main extends Sprite {

        private var _channel:SoundChannel;
        private var _graph:Sprite;

        public function Main() {
        Security.loadPolicyFile("http://navioo.com/crossdomain.xml");
            var sound:Sound = new Sound();
            sound.load(new URLRequest("http://navioo.com/Demo.mp3")new SoundLoaderContext(1000true));
            _channel = sound.play();
            _graph = new Sprite();
            _graph.y = 200;
            addChild(_graph);
            addEventListener(Event.ENTER_FRAME, enterFrameHandler);
        }

        private function enterFrameHandler(event:Event):void {
            var bytes:ByteArray = new ByteArray();
            SoundMixer.computeSpectrum(bytes);
            _graph.graphics.clear();
            _graph.graphics.lineStyle(001);
            var plotX:Number = 0;
            for(var i:Number = 0; i < 256; i++) {
                _graph.graphics.lineTo(plotX, bytes.readFloat() * stage.stageHeight / 2);
                plotX += stage.stageWidth / 256;
            }
        }
    }
}

        



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


Flash / Flex / ActionScript examples

 Navioo Development
» ByteArray