Flash Audio: Pausing Sounds in Flash

This tutorial will show you how to create a pause button for the music loops you have added in the first tutorial.
This tutorial is built on top of the the tutorial ‘Creating a Sound On/Off Buttons’. You should complete the tutorial successfuly. Click here to open the tutorial. When you complete it you can come back here. Open the library from this tutorial and double click the button in library. Rename the button the ‘PauseSoundButton’ (Image 1).

creating a pause button for ausio in flash

Right click on the button and click ‘Edit…’. Remove the speaker graphic and add a simple text like ‘Pause Sound’ (Image 2).

creating a pause button for audio in flash

It’s noting spectacular as you can see, but up to you how you create your graphics. You can add what you want into the button.

As left from the previous tutorial, the button should be placed in the upper  right corner. Now click on the first frame of the ‘Actions’ layer, press F9 to open up the Actions panel. Remove the code from the previous tutorial and add the following code:

var mySound:Sound = new Sound();
mySound.attachSound("myTrack");
mySound.start();
var soundStarted:Boolean = true;
var lastPosition:Number = 0;
sound_btn.onRelease = function() {
    soundStarted = !soundStarted;
    if (soundStarted) {
        this._alpha = 100;
        mySound.start(lastPosition);
        //mySound.
    } else {
        this._alpha = 30;
        mySound.stop();
        lastPosition = Math.floor(mySound.position / 1000);
    }
};

That’s it! You have a functional pause button!

About admin

My name is Mark Lewis. I own a few popular royalty free content websites. I have been helping musicians distribute their music for over 17 years now and wanted to use this forum to share thoughts and experiences and hopefully spark some discussion in regards to the distribution of royalty free music and royalty free content in general.