Catharsis
Catharsis

Reputation: 476

How do I set the width and height of my swf in AS3?

How do I set the width and height of my swf in AS3?

This is my code so far:

package {

    import flash.display.Sprite;
    public class Game extends Sprite {

    }

}

Right now, when loaded it is at some arbitrary default size.

If I can't change the size this way, is there any easy work around that will be consistent?

Upvotes: 2

Views: 9184

Answers (3)

Adam Harte
Adam Harte

Reputation: 10510

I know you say you want to set the size via AS3, but is that necessary? Can't you just set the output properties. If you are publishing from Flash IDE you can go to Modify > Document, and set the width and height.

In your AS3 you can set the following properties, so when your SWF resizes, it is handled better.

stage.scaleMode = StageScaleMode.NO_SCALE;
stage.align = StageAlign.TOP_LEFT;

EDIT

If you are using mxmlc in the command line to compile your SWF default size option:

default-size <width> <height>

Upvotes: 2

Karl Johan
Karl Johan

Reputation: 4022

Try putting

[SWF(backgroundColor="#000000", width="200", height="400", frameRate="29")]

In the line above

public class Game extends Sprite {
....

Where you, of course, can set backgroundColor, width, height etc. To whatever you want.

Hope it helps!

Upvotes: 10

CookieOfFortune
CookieOfFortune

Reputation: 13974

For the most part, I believe SWF size is generally controlled by the web page it's embedded into. The SWF does not have direct access to these properties, but I believe you can use Javascript and call it from the SWF. Here is a link to a discussion about doing this: Actionscript Forums

Upvotes: -1

Related Questions