Dynamically change stage color

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

Expert Comment

ID: 13991272
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.


Author Comment

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

Expert Comment

ID: 13991879
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

sam85281 earned 1000 total points
ID: 13992365
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

ID: 13992386
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

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I come across a lot of question about how to access things in the document class from a movieclip, or accessing something from a movieclip in the document class. It took me a while to figure this out but once I did it makes life so much easier. …
In my long career of working as an actionscript developer, I had spent sleepless night often working hard to solve some small problems which actually took a lot of my development time; later found out the solutions to be a line or two. Here are s…
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.
Suggested Courses

850 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