如何在UILoader中对齐照片中心?

时间:2013-01-31 23:27:35

标签: actionscript-3 flash hosting dreamweaver flash-cs5

我制作了一个照片库,我使用Flash cs5 As3 UILoader组件,如何在中心加载所有不同尺寸的照片?左上角的Uiloader组件注册,我需要到中间? 阶段1000 px宽,420px highth。

我的照片大小不同,有些是803x400,有些是580x400,uiLoader注册点在左上角,这就是问题,如果我在中间制作了580x400,那么803x400px手机将会很远在右边。

有没有办法解决这个问题?

[www.bradmarkel.net] 点击野生动物,你会理解我的意思。

这是我的图库代码,感谢您的时间!

import flash.utils.Timer;
import flash.events.TimerEvent;
import flash.events.MouseEvent;
import flash.events.Event;
import fl.containers.UILoader;
import flash.text.TextField;
import flash.display.SimpleButton;
import fl.transitions.Tween;
import fl.transitions.TweenEvent;
import fl.transitions.easing.*;
stage.colorCorrection = ColorCorrection.ON;
var myImage:String = "smallNews/resized web news photos/00.jpg";
var request:URLRequest = new URLRequest(myImage);
uiLoader.addEventListener(Event.COMPLETE, completeHandler);
uiLoader.addEventListener(ProgressEvent.PROGRESS, progressHandler);
uiLoader.load(request);

function progressHandler(event:ProgressEvent):void
 {

status_txt.text = "Percentage Loaded: " + Math.round(event.target.percentLoaded);
 }

function completeHandler(event:Event):void
{
var spr = new Sprite();

// Place spr anywhere on the stage
spr.x = stage.stageWidth / 6 - uiLoader.content.width / 6;
spr.y = stage.stageHeight / 235 - uiLoader.content.height / 235;
spr.addChild( uiLoader );

addChild( spr );

// Center uiLoader in spr
uiLoader.x =  -  uiLoader.width / 500;
uiLoader.y =  -  uiLoader.height / 235;
new Tween(spr,"rotationX",Elastic.easeOut,45,0,4,true);
 }
 next_btn.addEventListener(MouseEvent.CLICK, nextImage);

 //variable is a container that holds some value...;
 var imageNumber:Number = 0;

 function checkNumber():void
 {
next_btn.visible = true;
back_btn.visible = true;
//If the imageNumber is = 47, then do something...
if (imageNumber == 24)
{
    trace(imageNumber);
    next_btn.visible = false;
}
//if the imageNumber is = 1, then don't show the back button
if (imageNumber == 0)
{
    trace(imageNumber);
        back_btn.visible = false;
}
      }
      checkNumber();

      function nextImage(evtObj:MouseEvent):void
      {
//Adding to the current value +1
imageNumber++;
uiLoader.source = "smallNews/resized web news photos/0" + imageNumber + ".jpg";
checkNumber();
      }

      back_btn.addEventListener(MouseEvent.CLICK, backImage);

      function backImage(evtObj:MouseEvent):void
      {
//Subtract 1 from the current value
imageNumber--;
uiLoader.source = "smallNews/resized web news photos/0" + imageNumber + ".jpg";
checkNumber();
       }

      stop();

1 个答案:

答案 0 :(得分:0)

你必须在容器的中心安排uiloader,如果我明白这样做的话:

function completeHandler(event:Event):void
{
var spr = new Sprite();

// Place spr anywhere on the stage
spr.x = stage.stageWidth / 6;
spr.y = stage.stageHeight / 235;
spr.addChild( uiLoader );

addChild( spr );

// Center uiLoader in spr
uiLoader.x =  -  uiLoader.content.width / 2;
uiLoader.y =  -  uiLoader.content.height / 2;
new Tween(spr,"rotationX",Elastic.easeOut,45,0,4,true);
 }