Resize container's content to fit
Hi all,
Looking for a bit of help with my AS3 project.
I have a stage with Top, Middle & Bottom Movieclip's set on it. On resize the content is scaled to fit and maintain the correct proportions.
I am loading each content (page) in as external SWF files into the Middle container using a Loader and URLRequest.
Here is my onCompleteHandler function:
Actionscript Code:
function onCompleteHandler(loadEvent:Event){
// Remove Preloader
middle.removeChild(preload);
content = MovieClip(loadEvent.currentTarget.content );
//the dimensions of the middle container
var _width:int = middle.width;
var _height:int = middle.height;
// Add content to middle
middle.addChild(content);
// Resize content to fit container
resizeMe(content, _width, _height, true);
// Center Content (rounded to nearest pixel to keep things sharp)
content.x = Math.round((_width - content.width)/2);
content.y = 0;
}
//The resizing function
function resizeMe(mc:MovieClip, maxW:Number, maxH:Number=0, constrainProportions:Boolean=true):void{
maxH = maxH == 0 ? maxW : maxH;
mc.width = maxW;
mc.height = maxH;
if (constrainProportions) {
mc.scaleX < mc.scaleY ? mc.scaleY = mc.scaleX : mc.scaleX = mc.scaleY;
}
}
This loads in the content and should resize it to fit within the Middle container whilst maintaining the proportional ratio of the content.
It seems to work fine when loaded in initially but after the browser is resized and the width/height of the Middle container have changed the content loads in much larger than the container.
It seems to be ignoring the new width/height of the Middlecontainer.
Could anybody shed some light as to why it might be doing this or what I can do to fix this?
Thanks very muxh