【问题标题】:Flash Builder: Change stage background color with AS3Flash Builder:使用 AS3 更改舞台背景颜色
【发布时间】:2012-07-08 09:22:02
【问题描述】:

我不是在谈论元/绑定,例如:

[SWF(backgroundColor="0xec9900")]

我需要能够即时更改颜色。

【问题讨论】:

标签: actionscript-3 flex4 flash-builder


【解决方案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 );

【讨论】:

  • bg ||= new Sprite(); ? ||= 有什么作用?
  • 那是惰性实例化。简写:if (bg == null) bg = new Sprite();
  • 当你说“似乎不起作用”是什么意思?错误?不是想要的效果?我已经测试了代码 - 它对我来说很好。
【解决方案2】:

我在我的主要精灵中使用它:

this.opaqueBackground = 0xff0000;

【讨论】:

    【解决方案3】:

    在初始化时我放了:

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

    【讨论】:

      猜你喜欢
      • 2011-03-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-11-22
      • 1970-01-01
      • 1970-01-01
      • 2015-05-01
      • 1970-01-01
      相关资源
      最近更新 更多