function setImgSize(img:Loader,limitedWidth:Number,limitedHeight:Number):void { if (img.width>limitedWidth) { img.height=limitedWidth/img.width*img.height; img.width=limitedWidth; } if (img.height>limitedHeight) { img.width=limitedHeight/img.height*img.width; img.height=limitedHeight; } }
function setImgSize(img:Loader,limitedWidth:Number,limitedHeight:Number):void { if (img.width<=limitedWidth&&img.height<=limitedHeight) { //不需要执行任何操作 } else { if (img.width/limitedWidth>=img.height/limitedHeight) { img.height=limitedWidth/img.width*img.height; img.width=limitedWidth; } else { img.width=limitedHeight/img.height*img.width; img.height=limitedHeight; } } }