2 Replies Latest reply on Jun 26, 2016 1:29 PM by forumsman.

    Can I add an audio visualizer to my Flash project?


      Hello, I would like to know if it's possible to add a simple audio visualizer that reacts to streaming audio in the timelines of movie clips. Is this possible with AS3? (I'm very new to Actionscript, sorry ^^)


      I was thinking of something like this:


        • 1. Re: Can I add an audio visualizer to my Flash project?
          kglad Adobe Community Professional & MVP



          in the as3 help files, check the static computeSpectrum method of the SoundMixer class.  there's sample code that shows how to create a spectrum analyzer:


          package {

              import flash.display.Sprite;

              import flash.display.Graphics;

              import flash.events.Event;

              import flash.media.Sound;

              import flash.media.SoundChannel;

              import flash.media.SoundMixer;

              import flash.net.URLRequest;

              import flash.utils.ByteArray;

              import flash.text.TextField;


              public class SoundMixer_computeSpectrumExample extends Sprite {


                  public function SoundMixer_computeSpectrumExample() {

                      var snd:Sound = new Sound();

                      var req:URLRequest = new URLRequest("Song1.mp3");



                      var channel:SoundChannel;

                      channel = snd.play();

                      addEventListener(Event.ENTER_FRAME, onEnterFrame);

                      channel.addEventListener(Event.SOUND_COMPLETE, onPlaybackComplete);



                  private function onEnterFrame(event:Event):void {

                      var bytes:ByteArray = new ByteArray();

                      const PLOT_HEIGHT:int = 200;

                      const CHANNEL_LENGTH:int = 256;


                      SoundMixer.computeSpectrum(bytes, false, 0);


                      var g:Graphics = this.graphics;




                      g.lineStyle(0, 0x6600CC);


                      g.moveTo(0, PLOT_HEIGHT);


                      var n:Number = 0;


                      for (var i:int = 0; i < CHANNEL_LENGTH; i++) {

                          n = (bytes.readFloat() * PLOT_HEIGHT);

                          g.lineTo(i * 2, PLOT_HEIGHT - n);



                      g.lineTo(CHANNEL_LENGTH * 2, PLOT_HEIGHT);



                      g.lineStyle(0, 0xCC0066);

                      g.beginFill(0xCC0066, 0.5);

                      g.moveTo(CHANNEL_LENGTH * 2, PLOT_HEIGHT);


                      for (i = CHANNEL_LENGTH; i > 0; i--) {

                          n = (bytes.readFloat() * PLOT_HEIGHT);

                          g.lineTo(i * 2, PLOT_HEIGHT - n);



                      g.lineTo(0, PLOT_HEIGHT);




                  private function onPlaybackComplete(event:Event):void {

                      removeEventListener(Event.ENTER_FRAME, onEnterFrame);




          1 person found this helpful
          • 2. Re: Can I add an audio visualizer to my Flash project?

            where do i enter this code?