Flash CS3 Documentation |
|||
| Programming ActionScript 3.0 > Working with sound > Playing sounds > Pausing and resuming a sound | |||
If your application plays long sounds, like songs or podcasts, you probably want to let users pause and resume the playback of those sounds. A sound cannot literally be paused during playback in ActionScript; it can only be stopped. However, a sound can be played starting from any point. You can record the position of the sound at the time it was stopped, and then replay the sound starting at that position later.
For example, let's say your code loads and plays a sound file like this:
var snd:Sound = new Sound(new URLRequest("bigSound.mp3"));
var channel:SoundChannel = snd.play();
While the sound plays, the SoundChannel.position property indicates the point in the sound file that is currently being played. Your application can store the position value before stopping the sound from playing, as follows:
var pausePosition:int = channel.position; channel.stop();
To resume playing the sound, pass the previously stored position value to restart the sound from the same point it stopped at before.
channel = snd.play(pausePosition);
Flash CS3
RSS feed | Send me an e-mail when comments are added to this page | Comment Report
Current page: http://livedocs.adobe.com/flash/9.0/main/00000290.html
Comments
No screen name said on Aug 14, 2007 at 10:54 AM : gerry-39 said on Oct 4, 2007 at 10:29 AM :