Dynamically change stage color

Posted on 2005-05-12
Last Modified: 2008-02-01
Is there a way to change the stage color on a button press?
Question by:skibama1
    LVL 18

    Expert Comment

    you can use this:
    my_color = new Color(targetmc);

    to dynamically change the colour of a clip - but not directly to the stage colour - create a stage sized square mc, lay it underneath everything else and give it an instance name to reference as above.

    LVL 1

    Author Comment

    That would work but is there not a way to change the stage color itself.
    LVL 18

    Expert Comment

    not really - an idea just popped into my head - dont know if it will work - you could try loading an swf with a different colour bg to the main underneath it (the _level0 clip is the one that holds the bg colour) that may be a way of doing it if you are trying just so you know you can.
    O/w, go with the mc on stage

    LVL 16

    Accepted Solution

    Javascript can do that for you....

    In the <head>  of your doc put:

    var newColor = new Array();
    newColor[0] = "#FF00FF"; // designate all your colors in this array
    newColor[1] = "#00FFFF";
    newColor[2] = "#FFFF00";
    newColor[3] = "#FF0000";
    function changeBG(myColor){
    window.document.getElementById("Untitled-1").bgcolor = newColor[myColor]; // Change Untitled-1 to match the ID in your object tag.

    In your object and embed tags, change bgcolor to be blank i.e. bgcolor=""

    That's it.  To call it from within flash on a button, etc.
    on (release) {
    getURL("javascript:changeBG(#);"); // Change # to the number that matches the color you want to change to.

    To call from the html doc:
    <a href="javascript:void(0)" onClick="changeBG(#);">Change Color</a>  Be sure to change # to the array index no that matches the color you want.

    LVL 16

    Expert Comment

    By the way, because bgcolor is set to blank you need to set an initial color with actionscript or it will default to your body bgcolor.

    To do this, in frame one pu this action:

    getURL("javascript:changeBG(#);"); // Once again that should be the number (0,1,2,etc) that mayches the color designated in the array.

    Also note that to test this you need to run the html file that contains the movie.  Trying to run just the swf or using ctrl+enter will just open a blank window.

    Because of this, I usually save that stuff for last in the project so it's not so annoying during the design process.


    Featured Post

    Maximize Your Threat Intelligence Reporting

    Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

    Join & Write a Comment

    I know the transition can be hard. We got used to the ease of use ActionScript 2 had, but honestly, it became problematic later on, especially if designers were involved in the project and found it easy to add code as they saw fit. So, this artic…
    While working over numerous projects I often had the requirement for doing a screen capture in AS3.0. Unfortunately I found no "ready made" solutions in google search that suited my requirements. But I did come across some great resources which help…
    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.
    This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.

    754 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

    19 Experts available now in Live!

    Get 1:1 Help Now