Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Use code to change background color in AS3?

Is it possible to change the stage's background through actionscript?

How do I do it? (Code please.)

like image 829
Moshe Avatar asked Nov 09 '10 20:11

Moshe


2 Answers

The stages background color can be changed using its graphics object.

If you have a reference to the stage:

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

If this is in your document class:

graphics.beginFill( 0x00FF00 );
graphics.drawRect( 0, 0, stage.stageWidth, stage.stageHeight );
graphics.endFill();
like image 110
Jordan Avatar answered Sep 29 '22 21:09

Jordan


I just wanted to add that the stage is kind of the exception of the rule. so to answer your question directly without a solution the answer is no you can't because the stage itself is by default empty with nothing on it. then added to Alan's answer the stage is kind of the ugly duck some of the properties that it inherits as it inherits it's properties from the DisplayObjectContainer don't apply such as you can't set a mask to the stage or change it's x,y and so on. so you can't change the background but Alan's solution is perfect you draw dynamically a shape and place it on your stage and then give it what ever color you want.

like image 33
Ben Fhala Avatar answered Sep 29 '22 22:09

Ben Fhala