title: Actionscript Loading/Calling Sounds From String Array
body: <p>i'm attempting to instantiate a bunch of sounds by creating a string array containing each sound's filepath (or name).</p>
  
  <pre><code>var soundByName:Object = {};
  var channelByName:Object = {};
  var soundName:String;
  var channelName:String;
  loadSounds();
  
  function loadSounds():void
      {
      var files:Array = new Array("sound1.mp3", "sound2.mp3"); //etc.
      for (var i:int = 0; i &lt; files.length; i++)
          {
          soundName = files[i];
          soundByName.soundName = new Sound();
          soundByName.soundName.addEventListener(Event.COMPLETE, sound_completeHandler);
          soundByName.soundName.addEventListener(IOErrorEvent.IO_ERROR, sound_ioErrorHandler);
          soundByName.soundName.load(new URLRequest(soundName));
          }
      }
  
  function sound_completeHandler(e:Event):void
      {
      channelName = e.currentTarget.name;
      channelByName.channelName = new SoundChannel();
      }
  
  function sound_ioErrorHandler(e:IOErrorEvent):void
      {
      trace("Failed To Load Sound:" + e.currentTarget.name);
      }
  </code></pre>
  
  <p>then called like this:</p>
  
  <pre><code>//Stop a sound
  channelByName["sound1.mp3"].stop();
  
  //Play a sound
  channelByName["sound2.mp3"] = soundByName["sound2.mp3"].play();
  </code></pre>
  
  <p>my current code contains an error from the sound_completeHandler() function stating that the 'name' property wasn't found.  i can't figure out how to add this name property, or how else to reference the e.currentTarget.</p>