0 Replies Latest reply on Oct 16, 2010 5:56 AM by proyb

    Fade out MP3 individually

    proyb

      Tie this code to a button, if I repetitive press as  fast as I can, an error exception would appear in the application. I  found that it would not throw an error if I stop the sound when it  completely fade out. However, I wish the fade out function could stop  the sound individually, not stop o1_1 together. Similar to a piano keyboard, how do I do that?


      private var s1_1:Sound = new Sound();
      private var o1_1:SoundChannel = new SoundChannel();

      private static const a1_1:String = "1.mp3";

      private
      function p1_1():void{
      s1_1
      = new Sound();
      s1_1
      .load(new URLRequest(a1_1));
      o1_1
      =s1_1.play();
      }

      private function fade1_1():void{
      TweenMax.to(o1_1, .35, {volume:0, onComplete:stop1_1});
      }

         
      private function stop1_1():void {
      //if I add, this code would only stop the sound altogether rather than individual. I wish to have each of the instance stop itself.
          o1_1
      .stop();
      }


      My error exception in Flex builder 3 using SDK 3.5 and AIR 2.0:
      [SWF] snd.swf - 1,022,361 bytes after decompression
      TypeError: Error #1009: Cannot access a property or method of a null object reference.
           at snd/st1_1()[...snd.mxml:44]
           at snd/___snd_Button1_mouseUp()[...snd.mxml:67]