Skip to main content
April 13, 2010
Question

Image resizing

  • April 13, 2010
  • 1 reply
  • 253 views

I'm trying to run a function that determines the image size coming in, and automatically rescaling itself based on the document size, but don't get where I'm going wrong

var imgLoader:Loader;

var container:Sprite;

initPic();

function initPic():void {

     imgLoader = new Loader();

     imgLoader.load(new URLRequest("Test Images/Tschichold.jpg"));

     imgLoader.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS,loadingInfo);

     imgLoader.contentLoaderInfo.addEventListener(Event.COMPLETE,imgLoaded);

}

function loadingInfo(e:ProgressEvent):void {

}

function imgLoaded(e:Event):void {

     var targetLoader:Loader = Loader(e.target.loader);

     var scaleCoord:Number = getScaleCoord(imgWidth,imgHeight);

     var imgWidth:Number = imgLoader.width;

     var imgHeight:Number = imgLoader.height;

     container = new Sprite();

     addChild(container);

     container.width = stage.stageWidth;

     container.height = stage.stageHeight;

     targetLoader.scaleX = scaleCoord;

     targetLoader.scaleY = scaleCoord;

     container.addChild(targetLoader);

}

function getScaleCoord(a:Number, b:Number):Number {

     var locX:Number = a;

     var locY:Number = b;

     var scaleCoord:Number;

     if (a > b * 1.214) {

          scaleCoord = stage.stageWidth/locX;

     }

     if (a < b * 1.214) {

          scaleCoord = stage.stageHeight/locY;

     }

     return scaleCoord;

}

This topic has been closed for replies.

1 reply

April 13, 2010

nvm, i converted it to a bitmap instead of img loader and a few other things and works now