AS3 XML幻灯片问题

时间:2010-02-19 21:38:13

标签: xml actionscript-3

我希望那里的某个人能够对我在图片幻灯片中遇到的几个问题有所了解

我一直在为一个项目做一个简单的幻灯片演示,一切都很好/正如预期的那样,直到我创建了一个函数来隐藏之前的图像,然后才显示下一个。在第一次通过一切似乎运行正常;一旦幻灯片重新开始,图像就不会显示,但是当它加载下面的图像时,它会从隐藏前一个功能播放补间,该功能在淡出之前会短暂显示图像。所以基本上显示器是空白的,然后计时器在下一张幻灯片中调用,并且图像的短暂闪烁逐渐淡出,然后再次为空白。

我遇到的另一个问题是我从XML加载的文本似乎不想按照它们应该进行补间。

以下是代码:

import fl.transitions.Tween;
import fl.transitions.easing.*;
import fl.transitions.TweenEvent;
import flash.display.BitmapData;
import flash.display.Bitmap;
import flash.display.Sprite;
import flash.utils.Timer;
import flash.events.TimerEvent;

var filePath:String = "photo1.xml";

var iArray:Array = new Array();
var titleArray:Array = new Array();
var dateArray:Array = new Array();
var catArray:Array = new Array();
var descArray:Array = new Array();

var rotationSpeed:Number;
var totalImages:Number;
var dataList:XMLList;
var imagesLoaded:Number = 0;
var currImage:Number = 0;
var rotationTimer:Timer;
var oldTween:Tween;
var imageContainer:Sprite = new Sprite();
var imageHolder:Sprite = new Sprite(); 
var titleContainer:Sprite = new Sprite();
var dateContainer:Sprite = new Sprite();
var catContainer:Sprite = new Sprite();
var descContainer:Sprite = new Sprite();
var theMask:Sprite = new Sprite();
theMask.graphics.beginFill(0x000000);
theMask.graphics.drawRect(114, 25, 323, 332);
addChild(theMask);

var loader:URLLoader = new URLLoader();

loader.addEventListener(Event.COMPLETE, onComplete);
loader.load(new URLRequest(filePath));

function onComplete (evt:Event):void{

 var pigData:XML = new XML(evt.target.data);
 pigData.ignoreWhitespace;
 dataList = pigData.pic;
 totalImages = dataList.length();
 rotationSpeed = pigData.@speed * 1000;
 stage.scaleMode = StageScaleMode.NO_SCALE;

 loadImages();

 rotationTimer = new Timer(rotationSpeed);
 rotationTimer.addEventListener(TimerEvent.TIMER, rotateImage);
 rotationTimer.start();

}

function loadImages() {
 for (var i:Number = 0; i < totalImages; i++) {

  var imageURL:String = dataList[i].big;
  var imageLoader:Loader = new Loader();
  imageLoader.load(new URLRequest(imageURL));
  imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, imageLoaded);
  iArray.push(imageLoader);

  var titleField:TextField = new TextField();
  var dateField:TextField = new TextField();
  var catField:TextField = new TextField();
  var descField:TextField = new TextField();

  titleField.text = dataList[i].title;
  titleField.autoSize = TextFieldAutoSize.LEFT;
  titleArray.push(titleField);

  dateField.text = dataList[i].date;
  dateField.autoSize = TextFieldAutoSize.LEFT;
  dateArray.push(dateField);

  catField.text = dataList[i].category;
  catField.autoSize = TextFieldAutoSize.LEFT;
  catArray.push(catField);

  descField.text = dataList[i].description;
  descField.autoSize = TextFieldAutoSize.LEFT;
  descArray.push(descField);
 }
}

function imageLoaded(evt:Event):void {

 imagesLoaded++;
 if (imagesLoaded == totalImages) {
  showImage();
 }
}

function showImage():void {
 addChild(imageContainer);
 imageContainer.addChild(imageHolder);
 imageContainer.addChild(titleContainer);
 imageContainer.addChild(dateContainer);
 imageContainer.addChild(catContainer);
 imageContainer.addChild(descContainer);
 changeImage();
}

function changeImage():void {
 var currentImage:Loader = Loader(iArray[currImage]);
 imageHolder.addChild(currentImage);
 currentImage.x = (stage.stageWidth - currentImage.width)/2;
 currentImage.y = (imageHolder.height - currentImage.height)/2; 
 imageHolder.mask = theMask;
 new Tween(imageHolder, "alpha", Regular.easeOut, 0, 1, 1, true);

 var titleField:TextField = TextField(titleArray[currImage]);
 titleContainer.addChild(titleField);
 titleField.x = 107;
 titleField.y = 365;
 var titleTween:Tween = new Tween(titleField, "alpha", Regular.easeOut, 0, 1, 1, true);

 var dateField:TextField = TextField(dateArray[currImage]);
 dateContainer.addChild(dateField);
 dateField.x = 107;
 dateField.y = 375;
 var dateTween:Tween = new Tween(dateField, "alpha", Regular.easeOut, 0, 1, 1, true);


 var catField:TextField = TextField(catArray[currImage]);
 catContainer.addChild(catField);
 catField.x = 107;
 catField.y = 385;
 var catTween:Tween = new Tween(catField, "alpha", Regular.easeOut, 0, 1, 1, true);

 var descField:TextField = TextField(descArray[currImage]);
 descContainer.addChild(descField);
 descField.x = 107;
 descField.y = 395;
 var descTween:Tween = new Tween(descField, "alpha", Regular.easeOut, 0, 1, 1, true);



}

function rotateImage(evt:TimerEvent) {
 hidePrev();

 currImage++;
 if (currImage == totalImages) {
  currImage = 0;
 }
 changeImage();
}

function hidePrev():void{

 var oldImage:Loader = Loader(imageHolder.getChildAt(0));
 oldTween = new Tween(oldImage,"alpha", Regular.easeOut, 1, 0, 1, true);
 oldTween.addEventListener(TweenEvent.MOTION_FINISH, onFadeOut)

 var oldTitle:TextField = TextField(titleContainer.getChildAt(0));
 var oldTitleTween:Tween = new Tween(oldTitle,"alpha", Regular.easeOut, 1, 0, 1, true);

 var oldDate:TextField = TextField(dateContainer.getChildAt(0));
 var oldDateTween:Tween = new Tween(oldDate,"alpha",Regular.easeOut,1,0,1,true);

 var oldCat:TextField = TextField(catContainer.getChildAt(0));
 var oldCatTween:Tween = new Tween(oldCat,"alpha",Regular.easeOut,1,0,1,true);

 var oldDesc:TextField = TextField(descContainer.getChildAt(0));
 var oldDescTween:Tween = new Tween(oldDesc,"alpha",Regular.easeOut,1,0,1,true);
}

function onFadeOut(evt:TweenEvent):void{
 imageHolder.removeChildAt(0);
 titleContainer.removeChildAt(0);
 dateContainer.removeChildAt(0);
 catContainer.removeChildAt(0);
 descContainer.removeChildAt(0);

}

我不是闪光的天才,赌注通常可以通过分析代码或在线挖掘来解决大多数问题;然而,这让我很难过。

真的很感激任何帮助,我提前感谢你们。

1 个答案:

答案 0 :(得分:0)

尝试将变量oldTitleTween,oldDateTween,oldCatTween,oldDescTween声明为全局变量,而不是将函数hidePrev()作为局部变量声明