I attached a fla (CS4), here's the code:
ActionScript Code:
import flash.events.MouseEvent;
increase_btn.addEventListener(MouseEvent.CLICK, onIncrease);
decrease_btn.addEventListener(MouseEvent.CLICK, onDecrease);
function onIncrease(evt:MouseEvent):void {
var inc:Number = .2;
var max:int = 150;
img_mc.scaleX += inc;
img_mc.scaleY += inc;
if (img_mc.width > max) {
img_mc.scaleX = img_mc.scaleY = 1;
img_mc.scaleX = img_mc.scaleY = max/img_mc.width;
}
if (img_mc.height > max) {
img_mc.scaleX = img_mc.scaleY = 1;
img_mc.scaleX = img_mc.scaleY = max/img_mc.height;
if (img_mc.width > max) {
img_mc.scaleX = img_mc.scaleY = 1;
img_mc.scaleX = img_mc.scaleY = max/img_mc.width;
}
}
centerImage();
}
function onDecrease(evt:MouseEvent):void {
var dec:Number = .2;
var min:int = 50;
img_mc.scaleX -= dec;
img_mc.scaleY -= dec;
if (img_mc.width < min) {
img_mc.scaleX = img_mc.scaleY = 1;
img_mc.scaleX = img_mc.scaleY = min/img_mc.width;
}
if (img_mc.height < min) {
img_mc.scaleX = img_mc.scaleY = 1;
img_mc.scaleX = img_mc.scaleY = min/img_mc.height;
if (img_mc.width < min) {
img_mc.scaleX = img_mc.scaleY = 1;
img_mc.scaleX = img_mc.scaleY = min/img_mc.width;
}
}
centerImage();
}
function centerImage():void {
img_mc.x = (stage.stageWidth-img_mc.width)/2;
img_mc.y = (stage.stageHeight-img_mc.height)/2;
}