i am loading an image with a loader, and in **onComplete **function i would like to call **calculateRatio **function and pass it Loader.content.width and Loader.content.height so it can compare it with the current stage width and height and resize image proporcionally to fit the screen.
how would i go about passing that parameters?
function callHomePage() {
bgLoader = new Loader();
bgLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, onComplete);
bgLoader.load(new URLRequest(bgArr[2]));
}
function onComplete(e:Event) {
bg_mc.addChild(bgLoader);
calculateRatio();
bg_mc.x = (stage.stageWidth / 2) - (bg_mc.width / 2);
bg_mc.y = (stage.stageHeight / 2) - (bg_mc.height / 2);
TweenLite.to(bg_mc, 3, {alpha:1});
}
function calculateRatio():void{
var destinationRatio:Number = stage.stageWidth / stage.stageHeight;// stage ratio
var targetRatio:Number = bgLoader.content.width / bgLoader.content.height;// body ratio
if (targetRatio < destinationRatio) {
bgLoader.content.height = (stage.stageWidth / bgLoader.content.width) * bgLoader.content.height;
bgLoader.content.width = stage.stageWidth;
} else {
bgLoader.content.width = (stage.stageHeight / bgLoader.content.height) * bgLoader.content.width;
bgLoader.content.height = stage.stageHeight;
}
}