Anyone knows how to make bgImage align in the center on resize, instead of top left?
Stage.scaleMode = "noScale";
_global.imgConstantWidth = bgImage._width;
_global.imgConstantHeight = bgImage._height;
// ---------------- Function to Set Movieclip at Top-Left ----------------
setImage = function(mc){
var originalWidth = 1000;
var originalHeight = 650;
var widthGutter = (Stage.width - originalWidth)/2;
var heightGutter = (Stage.height - originalHeight)/2;
mc._x = -widthGutter;
mc._y = -heightGutter;
}
// ---------------- Function to Resize/Crop Movieclip to Stage Size ----------------
resizeImage = function(mc){
var scaleByWidth;
if (Stage.width/Stage.height > _global.imgConstantWidth/_global.imgConstantHeight){
scaleByWidth = true;
}else{
scaleByWidth = false;
}
if (scaleByWidth){
mc._height = Stage.width * _global.imgConstantHeight / _global.imgConstantWidth;
mc._width = Stage.width;
} else {
mc._width = Stage.height * _global.imgConstantWidth / _global.imgConstantHeight;
mc._height = Stage.height;
}
}
// ------------- Set Image on Load -------------
setImage(bgImage);
resizeImage(bgImage);
// ------------- Set Image on Resize -------------
sizeListener = new Object();
sizeListener.onResize = function() {
setImage(bgImage);
resizeImage(bgImage);
};
Stage.addListener(sizeListener);