views:

175

answers:

4

Hi guys... I am using pure AS3 to build my project. I was wondering if there are anyways to change the stage background color through AS3...Thanks for the help....

A: 

Try setting the backgroundColor of the application object.

Robusto
Thanks...would you please explain more details? I have tried google but couldn't find anything.....Thanks.
Jerry
+2  A: 

like this:

[SWF(backgroundColor="0xec9900")]
public class Main extends Sprite
{
    }
PatrickS
+3  A: 

You can set background colour on initialization, the way @Wopdoowop mentioned, but if you want to change it dynamically you would need to create your own bitmap/sprite/movieclip that would act as a background (should go below the rest of your content and have width and height of your stage) and change colour of that bitmap/sprite/movieclip.

negative
+1  A: 

This creates a shape and add it to the stage behind everything. To change the color anytime call: changeBGColor(0xFF0000) (to red)

It also maintains the size of the background (covering all area) when the windows is resized.

import flash.display.Sprite;
import flash.events.Event;

var default_bg_color:uint = 0xffffff;

var bgshape:Sprite;
stage.align = "TL";
stage.scaleMode = "noScale";

function initBG()
{
    bgshape = new Sprite();
    bgshape.graphics.beginFill(default_bg_color);
    bgshape.graphics.drawRect(0,0,stage.stageWidth, stage.stageHeight);
    addChildAt(bgshape, 0);
    stage.addEventListener(Event.RESIZE, resizeBGWithStage);
}
function changeBGColor(color:uint) 
{
    bgshape.graphics.beginFill(color);
    bgshape.graphics.drawRect(0,0,stage.stageWidth, stage.stageHeight);
}
function resizeBGWithStage(e:Event)
{
    try {
        bgshape.width = stage.stageWidth;
        bgshape.height = stage.stageHeight;
    } catch(e){}
}

initBG();
Makram Saleh
Thanks Makram...but Wopdoowop's way is much easier... :D +1 though
Jerry