Peter Hall posted a solution to setting the background color using Actionscript, actually drawing a rectangle on the background below any other elements on the document. Someone on the Macromedia Flash Forum re-iterated that question, so I thought some of you may still would like to have a look at a modified version.
This one will only fill the viewable stage and not the whole maximum allowable space of 5760 px of the Flash Document Scene. Code follows in the full message.
//define a var for sh and sw
//let us add 2 px each as flash eats them
//in the Stage Object from the actual flash dimension
var sh = Stage.height + 4;
var sw = Stage.width + 4;
var rp = 0;//let us have a start point
trace("stage height = " + sh + " & stage width = " + sw + " in pixels");
setBG = function (col) {
with (_level0) {
clear();
if (col != undefined) {
beginFill(col);
moveTo(rp, rp);
lineTo(sw, rp);
lineTo(sw, sh);
lineTo(rp, sh);
endFill();
}
}
this.__bg__ = col;
};
//
getBG = function () {
return this.__bg__;
};
//
Stage.addProperty("bgColor", getBG, setBG);
delete setBG;
delete getBG;
//Usage
Stage.bgColor = 0x0000ff;
Brajeshwar posted this article
on Tue, Feb 18th, 2003 at 5:20 pm
Categorized under Technology and has the following tags






Comments Post Yours
There are 15 responses so far. You can follow any responses to this entry through the RSS feed. You can skip to the end and leave a response. Pinging is currently not allowed.
Thanks brajeshwar This should come in handy.
I noticed a couple of problems, This fixes it(replace existing code with ):
var sw = Stage.width + 4;
and….
beginFill(col);
moveTo(rp, rp);
lineTo(sw, rp);
lineTo(sw, sh);
lineTo(rp, sh);
endFill();
Updated! I did not even test the code beforehand, hhhmmmm. I will take care next time.
If you change the code to the following,
it also works when you have the Stage.scaleMode set to “NoScale”, and the Stage.align to “LT”
// We don't want the Flash to Scale // but use dynamic alignment instead Stage.scaleMode = "noScale" Stage.align = "LT" var rp = 0;//let us have a start point setBG = function (col) { with (_level0) { clear(); if (col != undefined) { beginFill(col); moveTo(rp, rp); //let us add 2 px each as flash eats them //in the Stage Object from the actual flash dimension lineTo(Stage.width + 4, rp); lineTo(Stage.width + 4, Stage.height +4); lineTo(rp, Stage.height +4); endFill(); } } this.__bg__ = col; }; // getBG = function () { return this.__bg__; }; // Stage.addProperty("bgColor", getBG, setBG); // add a listener to _level0 // so that the bg is redrawn when a user resizes the Stage Stage.addListener(_level0) _level0.onResize = function (){Stage.bgColor = Stage.bgColor} delete setBG; delete getBG; //Usage Stage.bgColor = 0x0000ff;// property:
MovieClip.prototype.addProperty(”bkColor”, function () { return this.bkColor }, function © {
if (arguments.length <= 0) return;
var n = this == _root ? {_width : Stage.width + 4, _height: Stage.height + 4} : this;
with (this) {
clear();
beginFill©;
lineTo(n._width, 0);
lineTo(n._width, n._height);
lineTo(0, n._height);
endFill();
}
this.__proto__.bkColor = c;
});
// usage:
this.bkColor = 0xFF0000;
trace(this.bkColor);
Hey there!
This script is just what i was looking for but it has one problem it seems.
For cdrom use i am making a fullscreen projector using these FScommands:
fscommand(”fullscreen”, “true”);
fscommand(”showmenu”, “false”);
fscommand(”allowscale”, “false”);
Now, when i add this script the background color change works but it does not change the complete background though. it starts it only at the left top of the flash document (at position 0,0). So the top and the right part of the monitor window will be the old background color. How can i fix this and be sure it will work on all resolutions? btw, im a total newbie at actionscripting i have to admit.
Greets,
David
David, just replace the initials variables that defines initial position, stage height and stage width to be full screen, in short, use this instead
moveTo(-2880, -2880);
lineTo(-2880, 2880);
lineTo(2880, 2880);
lineTo(2880, -2880);
lineTo(-2880, -2880);
AHa great, Thanks!
What we tried was this;
var sh = Stage.height + 3000;
var sw = Stage.width + 3000;
var rp = -1200;//let us have a start point
cheers,
David
one more question now were at it, I am starting with a white background that turns darkblue at scene 2. would it be possible to gradually fade it from white to blue instead of having it switch instantly over 25 frames time for instance?
:p
can you insert the date to the comments? it would be helpful
i need your help urgently if you feel free and having little bit time to give me to answer my few question that i have bg compenet i have seen your given code and try its work fine after fixing small erors. i want to edit bg color from external text file can you help me to solve this issue actully i have not much experaince in flash i am new but i can say i can work little bit good ………..i hope you will reply me as soon as possible when you have spare time….
I keep getting a static script error on this code? i’m using Mx pro 2004? Please help…
You are very welcome to visit my website.
Johny Hobson o
I like this BUT just wondering what the ‘this.__bg__ = col;’ and ‘return this.__bg__’ are for??
Could this dynamic background color, script by any chance be put into flash 8 scripting. I have tryed but cant seem to figure it out. Thank you.
//define a var for sh and sw //let us add 2 px each as flash eats them //in the Stage Object from the actual flash dimension var sh = Stage.height + 4; var sw = Stage.width + 4; var rp = 0;//let us have a start point trace("stage height = " + sh + " & stage width = " + sw + " in pixels"); setBG = function (col) { with (_level0) { clear(); if (col != undefined) { beginFill(col); moveTo(rp, rp); lineTo(sw, rp); lineTo(sw, sh); lineTo(rp, sh); endFill(); } } this.__bg__ = col; }; // getBG = function () { return this.__bg__; }; // Stage.addProperty("bgColor", getBG, setBG); delete setBG; delete getBG; //Usage Stage.bgColor = 0x0000ff;Post yours