proyb2
asked on
How to fade out individual sound instead of all?
Tie this code to a virtual piano keyboard which is a mx:button.
I tried to press the button repetitive as fast as I can, it will throw an error exception and cause the AIR application to hang.
I found that it would not throw an error if I stop the sound channel when it completely fade out. However, I wish the function could fade out and stop the sound individually, not stop o1_1 together. How do I do that?
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]
I tried to press the button repetitive as fast as I can, it will throw an error exception and cause the AIR application to hang.
I found that it would not throw an error if I stop the sound channel when it completely fade out. However, I wish the function could fade out and stop the sound individually, not stop o1_1 together. 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";
//button press would execute p1_1
private function p1_1():void{
s1_1 = new Sound();
s1_1.load(new URLRequest(a1_1));
o1_1=s1_1.play();
}
//Button not press would execute fade1_1
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 to fade our and stop itself should the user press and release.
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
ASKER
I tried your new code, however, the problem is still the same as before.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
You can leave out that SoundTransform variable. It's a really fun thing to play with, though, especially setting the pan value to very large positive or negative numbers.
ASKER
Oh, still the same error thou. I wonder was the Flash player's limitation?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
No solution, I will choose alternative solution for sound development
You could try listening for the loadComplete event before attempting to play, but I think it might be better to embed the sound in the application using mx.core.SoundAsset, which is an extension of flash.media.Sound that lets you do embedding.
You would want to place the sound file in a directory on the source path, and then the code might look something like this:
Open in new window