Fly*_*Cat 15 flash actionscript-3 background-color
我使用纯AS3来构建我的项目.我想知道是否有任何方式通过AS3改变舞台背景颜色...感谢您的帮助......
Pat*_*ckS 23
像这样:
[SWF(backgroundColor="0xec9900")]
public class Main extends Sprite
{
}
Run Code Online (Sandbox Code Playgroud)
Pet*_*son 10
我在creationComplete
处理程序中有这个
<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;
}
Run Code Online (Sandbox Code Playgroud)
虽然我有一种感觉它可以在任何地方工作.
这会创建一个形状并将其添加到一切背后的舞台上.随时改变颜色:( changeBGColor(0xFF0000)
红色)
调整窗口大小时,它还会保持背景的大小(覆盖所有区域).
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();
Run Code Online (Sandbox Code Playgroud)