views:

84

answers:

3

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?

A: 

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

CookieOfFortune
But what about non-web based SWFs? I am also making self contained swf exes.
Austin Kelley Way
+4  A: 

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!

Charlie boy
Pretty close to what I want, though it still feels kinda hacky. Do you know where I can find information on these [x()] codes?
Austin Kelley Way
I'm sorry, I don't really have any more information. I saw it in some tutorial a while ago, it was only there in passing.
Charlie boy
A: 

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>
TandemAdam
Not publishing from the FlashIDE. Don't have that kind of money. Besides, I'm trying to use pure actionscript.
Austin Kelley Way
So your using the Flex compiler (mxmlc) then? Are you using it manually (terminal)? or using an IDE like FlashDevelop?
TandemAdam
I'm using it manually.
Austin Kelley Way