title: AS3 playing audio and looping it
body: <p>I'm trying to get an audio file to play in the background of my project but so far have been unsuccessful so far. Heres what I've gotten so far.</p>
  
  <pre><code>package  {
  
      import flash.display.*; 
      import flash.events.*; 
      import flash.net.*; 
      import flash.media.*; 
  
      public class Music extends MovieClip {
  
          // Create a sound
          private var music:Sound;
  
          // Use a URLRequest for file path
          private var request:URLRequest;
  
          // Create a sound buffer
          private var buffer:SoundLoaderContext;
  
          // Create a sound channel
          private var channel:SoundChannel;
  
          public function Music() {
              // constructor code
              //Instantiate all sound objects
              buffer = new SoundLoaderContext(1000);
              request = new URLRequest("SMB3-Grassland-Map.mp3");
              music = new Sound(request, buffer);
  
              // Play music and assign it to a channel
              channel = music.play();
  
              // Add an event listener to the channel
              channel.addEventListener(Event.SOUND_COMPLETE, loopMusic);
          }
  
          // playMusic method restarts music
          private function playMusic()
          {
              channel = music.play();
              channel.addEventListener(Event.SOUND_COMPLETE, loopMusic);
          }
  
          // Channel event listener call playMusic method
          private function loopMusic(e:Event)
          {
              if (channel != null)
              {
                  channel.removeEventListener(Event.SOUND_COMPLETE, loopMusic);
  
                  playMusic();
              }
          }
  
      }
  }
  </code></pre>
  
  <p>this is just to play an external audio file and have it continually loop.</p>