AS3 MovieClip resize

1.8k Views Asked by At

I am trying to find AS3 code for a MovieClip on my stage. My stage resizes proportionally on different screens (different size monitors), but the MC gets too big for smaller screen laptops and some parts of it get cut off. Would appreciate for any help

2

There are 2 best solutions below

0
On

Put this before anything else. This code find's the scale size from your original layout to the re-sized. (NOTE: It's best if you use this when Event.RESIZE is happening)

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

var guiSize:Rectangle = new Rectangle(0, 0, 1024, 600); //original stage size, substitute this with your orginal size
var deviceSize:Rectangle = new Rectangle(0, 0,
Math.max(stage.fullScreenWidth, stage.fullScreenHeight),
Math.min(stage.fullScreenWidth, stage.fullScreenHeight));

var appScale:Number = 1;

if ((deviceSize.width/deviceSize.height) > (guiSize.width/guiSize.height)) {
    appScale = deviceSize.height / guiSize.height;
} 
else {
    appScale = deviceSize.width / guiSize.width;
}

Than, use appScale to scale every MovieClip/Sprite you have, e.g. _mc.scaleX = _mc.scaleY = appScale. Using this way, every time the stage get re-sized, the right and down border are moved. That means if you want your footer to be always 50px from bottom, you should use something like :

_footer.y = stage.stageHeight - (50 * appCale);
1
On

You could restrict any scaling, and handle the sizing yourself:

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

Have a look at the docs for the scale mode and align properties available.