Change stage background color in AS3?

2020-07-02 10:38发布

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....

8条回答
迷人小祖宗
2楼-- · 2020-07-02 11:02

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();
查看更多
叼着烟拽天下
3楼-- · 2020-07-02 11:08

like this:

[SWF(backgroundColor="0xec9900")]
public class Main extends Sprite
{
    }
查看更多
可以哭但决不认输i
4楼-- · 2020-07-02 11:11

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.

查看更多
The star\"
5楼-- · 2020-07-02 11:12

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;

查看更多
看我几分像从前
6楼-- · 2020-07-02 11:18

Try setting the backgroundColor of the application object.

查看更多
爱情/是我丢掉的垃圾
7楼-- · 2020-07-02 11:21
[SWF(width='700',height='525',backgroundColor='#000000',frameRate='30')]
public class RunTime extends Sprite {
查看更多
登录 后发表回答