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....
like this:
[SWF(backgroundColor="0xec9900")]
public class Main extends Sprite
{
}
I have this in a creationComplete
handler
<s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx"
creationComplete="on_init();">
private function on_init():void {
stage.color = 0x000000;
}
Though I have a feeling it would work anywhere.
addEventListener(Event.ADDED_TO_STAGE, onAddToStage);
(just remove the xml crap, I use pure AS3 and it works) –
Quinquagesima 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();
You should be able to use the following line of Actionscript 3.0 to set the background color. 0x000000 for black, 0xFFFFFF for white and anything in between.
this.stage.color = 0x00000;
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.
[SWF(width='700',height='525',backgroundColor='#000000',frameRate='30')]
public class RunTime extends Sprite {
Try setting the backgroundColor of the application object.
I suggest making a sprite and then making it in the back. This is the way I would do it.
Make sure to import flash.display.Sprite;
var bkg:Sprite=new Sprite();
//replace the 0x000000 with a hex code.
bkg.graphics.beginFill(0x000000, 1)
bkg.graphics.drawRect(0,0,stage.stageWidth,stage.stageHeight)
bkg.graphics.endFill()
addChild(bkg)
a plus about this is that you can draw a background (if you want) either manually or with the code and then put it in through the code.
© 2022 - 2024 — McMap. All rights reserved.
stage.color = 0xABCDEF
that gave Peter Gibson. – Commentator