Search code examples
actionscript-3propertiesbackground-colorstage

ActionScript - Why is there no backgroundColor property for Stage?


i can set the stage's background color, etc., using a SWF metadata tag:

[SWF(width="1024", height="600", frameRate="60", backgroundColor="#000000")]

or if i'm using Flash Professional, i can simply set these properties for the document in the UI.

while the Stage class offers the ability to set a frameRate and override width and height thru properties in actionscript, why is it not possible to set the background color of the stage the same way?

Stage doesn't have a property (public or otherwise) for background color. can anyone explain why that is? it seems strange to me but i'm assuming there is a good reason rather than this simply being a oversight.


Solution

  • The background color that you can set with the SWF metadata sets the default background color for the container that contains the SWF. If you use CSS (etc...) to manipulate that container's background-color property then it will change. You can also set wmode=transparent to show whatever content is rendered under the SWF in place of the background color.

    If you're using a standalone player it may or may not respect this metadata value. You probably shouldn't assume that it will. If you need to guarantee a given opaque background color then draw it onto your stage when you startup:

    graphics.beginFill(0xFF0000);
    graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
    graphics.endFill();