1

I create a movie clip of play and pause button, so that as the animation go, i just can pause at that frame and then play it to continue.But,as the cartoon character speak out voice/sound, when i pause it, the sound cannot be stopped.So, what should add into the script so that after play again, the sound will continue from where it stops.

Do i need to change the " var mySound:Sound = new MySound()" each time for the script as the sound file is different each time?

NemoStein
  • 2,088
  • 2
  • 22
  • 36
user2196021
  • 11
  • 2
  • 5
  • Set the sound to stream (on the timeline). Or take control of the SoundChannel. – Amy Blankenship Mar 27 '13 at 02:36
  • you can stop the time line with stop() check out out timeline control.// "Hence" currentFrame() – joshua Mar 27 '13 at 05:17
  • How to add in the SoundChannel actually?@AmyBlankenship How to set the stop() at the timeline of that sound which can be controlled by the stop button?@parele This is the AS3 for pause button. ` stop(); halt.addEventListener(MouseEvent.CLICK,stopplaying); function stopplaying (Event: MouseEvent):void { MovieClip(root).stop(); gotoAndStop(2); } ` This is the AS3 for play button. ` stop(); go.addEventListener(MouseEvent.CLICK,startplaying); function startplaying (Event: MouseEvent):void { MovieClip(root).play(); gotoAndStop(1); }` – user2196021 Mar 27 '13 at 08:48
  • You should record your sound channel position at the time of button click, then stop the sound, then at the time of resume, call `currentSound.play(recordedPosition,1)` to resume playback. The trouble is that if your sound is on the timeline, you will have difficulty capturing all the sounds that are in play at the particular frame. I don't yet know the method of retrieving sounds from the timeline, as well as retrieving sound channel creation events. Maybe there is some. – Vesper Mar 28 '13 at 05:12
  • Ya..I put the sound in the timeline.....that is why i wonder how am i going to pause the current sound at particular frame, then continue the sound at that frame... so how to make like other normal video player, we can stop the movie as well as sound of coz anytime.... – user2196021 Mar 28 '13 at 12:59

1 Answers1

0

When you play a sound by calling Sound.play() it returns a SoundChannel object.
Then, you can stop your sound by calling SoundChannel.stop().

The Sound.play() can receive a int parameter that tells the Sound to play from that millisecond.

And, the Sound object SoundChannel have a position property that tell you how much of the sound have played (in milliseconds).

To sum it up, you can do something like this:

private var mySound:Sound = new MySound();
private var mySoundChannel:SoundChannel;
private var latestPosition:int = 0;

public function play():void
{
    mySoundChannel = mySound.play(latestPosition);
}

public function pause():void
{
    latestPosition = mySoundChannel.position;
    mySoundChannel.stop();
}

public function stop():void
{
    latestPosition = 0;
    mySoundChannel.stop();
}
NemoStein
  • 2,088
  • 2
  • 22
  • 36