简体   繁体   中英

How do I change the size and color of the stage in actionscript 3?

AFAIK,在AS2中为“ Stage.height = x;”。

From documentation of flash.display.stage in AS3:

The Stage object is not globally accessible. You need to access it through the stage property of a DisplayObject instance.

Also refer to this: Setting Stage properties

You really can't... the background color is not really a stage property, you should work-around it by changing some background clip. As for the size, in AIR you can directly change the NativeWindow dimesions, but in a browser you need to use javascript to change the object's size:

document.getElementById("myFlash").height=100;

You could use stage.width = 100, but it will only change the displayobject's dimensions, truncating its content, and leaving an empty space next to it... Actually Stage.width is read-only in AS3 and AS2.

Depends on how you are compiling your .swf, but it is completely possible. If you are building a Flex project, you can set the backgroundColor property of the Application or use a css file to change it. eg

<mx:Application 
    backgroundColor="#000000" 
    width="500"
    height="500"
    layout="absolute"
    xmlns:mx="http://www.adobe.com/2006/mxml">

</mx:Application>

If you are building in Flex (an "Actionscript Project") or using the mxmlc compiler, you can use the undocumented "SWF" metadata tag, eg

package
{
    [SWF(width="500", height="500", backgroundColor="#000000")]
    public class MyApp extends Sprite
    {

    }
}

And of course, if you're using Flash "the application", you can just click the stage and then go to the properties panel and set the width, height, and background color.

This is easy. In the main CData block, "this" is the application object. Then:

this.setStyle("backgroundColor", 0xff0000);

This is much better than starting to creates sprites and rendering with the graphics layer, since presumably the best performance is with a flat fill in the absence of any objects in front.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM