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

别说谁变了你拦得住时间么 提交于 2019-12-10 11:25:37

问题


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?


回答1:


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!




回答2:


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>



回答3:


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



来源:https://stackoverflow.com/questions/3048116/how-do-i-set-the-width-and-height-of-my-swf-in-as3

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!