2012-07-08 32 views
1

我不是在談論元/結合,如:Flash Builder中:更改舞臺背景顏色與AS3

[SWF(backgroundColor="0xec9900")] 

我需要能夠動態更改顏色。

+0

希望這會爲你工作: http://stackoverflow.com/questions/3432408/change-stage-background-color-in-as3 – 2012-07-09 04:47:01

回答

1

在Sprite中繪製一個矩形,並將其作爲最低級別的子級添加到舞臺上。

var bg:Sprite; 

function changeStageColor(color : uint) : void { 
    bg ||= new Sprite(); 
    bg.graphics.clear(); 
    bg.graphics.beginFill(color, 1); 
    bg.graphics.drawRect(0,0, stage.stageWidth, stage.stageHeight); 
    bg.graphics.endFill(); 
    stage.addChildAt(bg, 0); 
} 

用法:

changeStageColor(0xFF0000); 
+0

bg || = new Sprite(); ? || =做什麼? – TheDarkIn1978 2012-07-09 01:58:29

+2

這是懶惰的實例。速記:'if(bg == null)bg = new Sprite();' – weltraumpirat 2012-07-09 06:51:01

+0

cool!我完全不知道這件事。 – TheDarkIn1978 2012-07-11 00:10:00

1

我在主體精靈使用:

this.opaqueBackground = 0xff0000; 
0

在初始化我把:

this.backgroundSkin = new Quad(this.stage.stageWidth, this.stage.stageHeight, 0x007800);