-
1. Re: Stop sound when object stops animating at end of stage
Peter Celuch Nov 14, 2011 9:47 AM (in response to EGBAR.Mary)You have to store reference to a SoundChannel that is created when Sound.play() is called.
var myChannel:SoundChannel = mySound.play();
then when you want the sound to stop, just call
myChannel.stop();
-
2. Re: Stop sound when object stops animating at end of stage
Peter Celuch Nov 14, 2011 9:53 AM (in response to EGBAR.Mary)The check you use won't work either. You would have to be calling it in onEnterFrame function, not just once. Try this instead:
var mySound:Sound = new bellsSound(); var myChannel:SoundChannel = mySound.play(); var myTween:Tween = new Tween(santa, "x", Regular.easeOut, -100, 810, 25, true); addChild(santa); addEventListener(Event.ENTER_FRAME, enterFrameHandler); function enterFrameHandler(event:Event):void { // or whatever check you need if(santa.x == 800) { myChannel.stop(); removeEventListener(Event.ENTER_FRAME, enterFrameHandler); } } -
3. Re: Stop sound when object stops animating at end of stage
Peter Celuch Nov 14, 2011 9:56 AM (in response to EGBAR.Mary)One more thing: try using free tweening library: TweenLite. It's really great library and doesn't suffer from defects like built-in Tween class. Forexample, Tween class can be garbage collected (stop functioning) if you forget to create an extra variable for it.
Also with TweenLite you wouldn't need enterFrame function. You could just add callback to be called when tween finishes.
-
4. Re: Stop sound when object stops animating at end of stage
EGBAR.Mary Nov 14, 2011 10:11 AM (in response to Peter Celuch)I've heard of that, but do I have to downlaod it from somewhere?
-
5. Re: Stop sound when object stops animating at end of stage
EGBAR.Mary Nov 14, 2011 10:13 AM (in response to Peter Celuch)Thank you!
The good news is that there are no errors. The bad news is that when my object(santa) reaches the end of the stage, the music continues to play.
-
6. Re: Stop sound when object stops animating at end of stage
Peter Celuch Nov 14, 2011 10:15 AM (in response to EGBAR.Mary)Yes, it's easy and free.
Click here: http://www.greensock.com/tweenlite/
In the top-right corner, there's a button DOWNLOAD AS3 - click and follow instructions..
On that page you can get all sorts of information you need to get started. It will take 15 minutes..
-
7. Re: Stop sound when object stops animating at end of stage
Peter Celuch Nov 14, 2011 10:20 AM (in response to EGBAR.Mary)Did you modify the IF statement? Put a trace in there so you can check if it triggers.
Where is your santa supposed to move? What is final x value? This should be in the IF statement.
myChannel.stop() has to work.
-
8. Re: Stop sound when object stops animating at end of stage
EGBAR.Mary Nov 14, 2011 10:35 AM (in response to Peter Celuch)I put a trace statement that was triggered when santa reached the end of the stage, however the bell sound continues to play.
-
9. Re: Stop sound when object stops animating at end of stage
EGBAR.Mary Nov 14, 2011 10:50 AM (in response to Peter Celuch)Does it matter what kind of sound file it is? It is a .wav file from istock.
I changed the final desitnation to 600 just to check and that is when the trace statement appeared, but the bell Sound continues to play.
-
10. Re: Stop sound when object stops animating at end of stage
Peter Celuch Nov 14, 2011 10:52 AM (in response to EGBAR.Mary)And the trace? Does it trace anything?
trace("Now should my sound stop");
myChannel.stop();
-
11. Re: Stop sound when object stops animating at end of stage
Peter Celuch Nov 14, 2011 10:54 AM (in response to EGBAR.Mary)I don't know what audio formats are supported, but if you can play it, you can stop it If it weren't supported, you wouldn't even start it.
-
12. Re: Stop sound when object stops animating at end of stage
EGBAR.Mary Nov 14, 2011 11:05 AM (in response to Peter Celuch)I had forgotten to delete the sound from the movieclip "santa". Now everything is working perfect. Thank you again for your help. Sorry for the confusion.
-
13. Re: Stop sound when object stops animating at end of stage
Peter Celuch Nov 14, 2011 11:10 AM (in response to EGBAR.Mary)Cool. No problem.

