Posted: February 17th, 2009 | Author: Janice | Filed under: Uncategorized | Tags: as3, flash | No Comments »
1
2
3
| private var container:MovieClip = new Container();
private var content:MovieCLip = new Content();
// where container is your stage, and content is the material you want to center |
Initialize your stage listeners/event listeners.
1
2
3
4
5
6
7
8
9
10
11
12
| function init() {
stage.align=StageAlign.TOP_LEFT;
stage.scaleMode=StageScaleMode.NO_SCALE;
stage.addEventListener(Event.RESIZE, updateSize);
stage.dispatchEvent(new Event(Event.RESIZE));
container.x = 0;
container.y = 0;
} |
updateSize gets called every time the stage gets resized.
1
2
3
4
5
6
7
8
9
10
11
| function updateSize(e:Event) {
// make container width/height equal to stage.width/height
container.width = stage.stageWidth;
container.height = stage.stageHeight;
//center content
content.x = stage.stageWidth/2 - content.width/2;
content.y = stage.stageHeight/2 - content.height/2;
} |
Leave a Reply