# Trouble with pausing and resuming sounds

**URL:** <https://forum.kirupa.com/t/trouble-with-pausing-and-resuming-sounds/301162>\
**Category:** Uncategorized\
**Created:** [December 4, 2009, 10:36am UTC](https://forum.kirupa.com/t/trouble-with-pausing-and-resuming-sounds/301162 "2009-12-04T10:36:21Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![benjamij](https://avatars.discourse-cdn.com/v4/letter/b/74df32/32.png) [@benjamij](https://forum.kirupa.com/u/benjamij)\
**Post date:** [December 4, 2009, 10:36am UTC](https://forum.kirupa.com/t/trouble-with-pausing-and-resuming-sounds/301162/1 "2009-12-04T10:36:21Z")

</div>

Hi, I have some trouble with pausing and then resuming sounds in as3.

```auto

package {
    import flash.media.Sound;
    import flash.media.SoundChannel;
    import flash.events.*;
    
    public class Sounds {
        var _main:Object;
        var soundsOn:Boolean;
        var songStarted:Boolean;
        var lastPosition:Number = 0;
        
        var fail_sound:Sound = new Shock();
        var audience:Sound = new audienceSound();
        var song_1:Sound = new song1();
        var song_2:Sound = new song2();
        //var background_music:SoundChannel;
        var channel:SoundChannel // = new SoundChannel();
        //var song_3:Sound = new song3();
        
        public function Sounds(m:Object):void {
            _main = m;
            soundsOn = true;
            channel = new SoundChannel();
        }
        
        public function init_sounds():void {
            songStarted = false;
            channel = audience.play();
            channel.addEventListener(Event.SOUND_COMPLETE, startSong);
        }
        
        private function startSong(e:Event):void {
            songStarted = true;
            channel.removeEventListener(Event.SOUND_COMPLETE, startSong);
            channel = song_1.play();
            channel.addEventListener(Event.SOUND_COMPLETE, end);
        }
        
        public function pauseSong():void {
            channel.stop();
            lastPosition = channel.position;
            trace(lastPosition);
            channel.removeEventListener(Event.SOUND_COMPLETE, startSong);
        }
        
        public function continueSong():void {
            //background_music.play(lastPosition);
            trace(lastPosition);
            if (songStarted) {
                channel = song_1.play(lastPosition);
                channel.addEventListener(Event.SOUND_COMPLETE, end);
            }
            else {
                channel = audience.play(lastPosition);
                channel.addEventListener(Event.SOUND_COMPLETE, startSong);
            }
        }

```

Pausing goes fine, however when I resume the song again, the sound starts playing a few seconds before I actually paused (so parts of the sound repeats itself). This is really annoying. Is there any way to fix this problem?

Thanks!
