为具有不同尺寸的所有图像自动调整大小

时间:2014-05-19 13:17:13

标签: actionscript-3 flash image-resizing image-size

我有一个imageshare.swf应用。我从" Images /" + imageNumber +" .jpg"拍照但是,我的所有照片都有不同的尺寸。例如970x700,580 * 441,500,500。我想把它们放到相同尺寸的舞台上。(固定500x500像素)。

import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.Event;
import flash.events.MouseEvent;
import fl.transitions.Tween;
import fl.transitions.easing.*;



//*****************CREATING VARIABLES*****************************//

//the array has all picture labels
//var myGlow:GlowFilter = new GlowFilter(0xffffff,1,10,10,255);// saving the glow
//var myShadow:DropShadowFilter = new DropShadowFilter(6);// saving the shadow to be applied later
var totalImages=11;
var imageNumber=1;

var myLoader:Loader = new Loader();


//************LOADING IMAGES TO STAGE********************//

var myRequest:URLRequest = new URLRequest("Images/"+imageNumber+".jpg");
myLoader.load(myRequest);
addChildAt(myLoader,1);// will be added under the buttons layer but over the texture

//************CENTERING THE PICS****************//

myLoader.contentLoaderInfo.addEventListener(Event.INIT, getImageInfo);
function getImageInfo(event:Event){
    var imgX=(stage.stageWidth- myLoader.width)/2;
    var imgY=(stage.stageHeight- myLoader.height)/2;
    myLoader.x=imgX;
    myLoader.y = imgY;// lines 37,38,39 & 40 are centering the loader formulae
    //myLoader.filters = [myGlow, myShadow];// adding a white color glow / grey shadow
    //var myTween:Tween = new Tween(myLoader, "alpha", None.easeNone, 0,1,2,true);//apply fade in

    }
//**************GOING TO NEXT IMAGE********************************//

rightButton.addEventListener(MouseEvent.CLICK, nextImage);
function nextImage(event:MouseEvent){
    if(imageNumber<totalImages)
    {
        imageNumber++;
    }
    else (imageNumber=1);
    reload();
    }
//**************GOING TO PREVIOUS IMAGE********************************//

leftButton.addEventListener(MouseEvent.CLICK, previousImage);
function previousImage(event:MouseEvent){
    if(imageNumber>1)
    {
        imageNumber--;
    }
    else (imageNumber=totalImages);
    reload();
    }

//*****************RELOADING****************************//
function reload(){
    removeChild(myLoader);
    myRequest= new URLRequest("Images/"+imageNumber+".jpg");
    myLoader.load(myRequest);
    addChildAt(myLoader,1);
    }

1 个答案:

答案 0 :(得分:2)

您设置xy属性的位置,请设置widthheight

myLoader.width = myLoader.height = 500;

顺便说一下,这会扰乱那些不完全平方的人,他们会看起来扭曲。