How to keep sound off after page change?

Posted on 2006-05-17
Last Modified: 2010-04-03


I found the page above on the Net and it has a nice simple way to make a sound on/off button, which I have used on my Flash file at:

The trouble is, when the user selects "Sound Off" and then changes pages and later returns to the (Flash) page, the sound defaults back to "on". How can one keep the "off" state in that case?

Question by:tallmax
    LVL 19

    Accepted Solution

    You can use SharedObjects to basically create a type of cookie on the user's machine. This "cookie" will keep the value of a variable, which you will check everytime the user visits the page.

    for example:

    this.onLoad = function(){


    // that's just an example that would have to be adjusted to fit your code.

    LVL 19

    Expert Comment

    This link has some general information about this, and could help you with your solution. If you're still having trouble, then please let me know and I'll be happy to help you further:


    Author Comment

    Hi Iammontoya!

    I grabbed your code and made a new layer on the main timeline (Scene 1) and added that code as an action script:

    this.onLoad = function(){
     if(soundOff = "true"){


    I'm no expert at actionscripting (sorry). The sound I have is on a layer with an instance name "music". Where in the example above would I change the code to fit my particulars? Can you highlight the sections?

    Your help is genuinely appreciated. Thanks.
    LVL 4

    Assisted Solution


    You have to save your state in a cookie:
    Frame 1:

    var dmcCookie = SharedObject.getLocal("cookietest","/");
    if( == undefined || == "ON"){
                    // default value is ON
 = "ON";
                    startTheSound(); // function that start the sound
    } else {
                   // do nothing

    Your clic on the button SwitchSound:
    on (release) {
          if( == "ON"){
       = "OFF";
                                    stopTheSound(); // function that stop the sound
       = "ON";
                                    startTheSound(); // function that start the sound


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Sometimes you know that one object has a specific child in it, but you can't find the child. This happened to me when I was trying to code some actionScript to make a toolbar work with its embedded buttons.  My partner had created the toolbar usi…
    I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
    In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
    The goal of the tutorial is to teach the user how to select the video input device. Make sure you have an input device that in connected and work and recognized by Adobe Flash Media Live Encoder and select it in the “video input” menu.

    794 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    17 Experts available now in Live!

    Get 1:1 Help Now