我有一个带有开始按钮的主菜单页面,然后在幻灯片上我有一个重新启动按钮,它可以进入主菜单。返回主菜单时如何停止幻灯片放映?现在我通过隐藏幻灯片组件并显示主页组件返回主菜单,但我无法停止幻灯片:
startButton.addEventListener(MouseEvent.CLICK, onStartClick);
restartButton.addEventListener(MouseEvent.CLICK, onRestartClick);
function onStartClick(event:MouseEvent):void{
populateArray();
TweenLite.to(titleScreen, 1, {alpha:0});
TweenLite.to(startButton, 1, {alpha:0});
TweenLite.to(theImage, 1, {alpha:1, delay:1});
TweenLite.to(infoBox, 1, {alpha:1, delay:1});
TweenLite.to(restartButton, 1, {alpha:1, delay:1});
beginImage();
}
//Go back to main menu
function onRestartClick(event:MouseEvent):void{
TweenLite.to(theImage, 1, {alpha:0});
TweenLite.to(infoBox, 1, {alpha:0});
TweenLite.to(restartButton, 1, {alpha:0});
TweenLite.to(titleScreen, 1, {alpha:1, delay:1});
TweenLite.to(startButton, 1, {alpha:1, delay:1});
}
function populateArray():void {
//takes the properties defined in the XML and stores them into arrays
var i:Number;
for (i = 0; i < listLength; i++) {
imageArray[i]=xml.images[i].pic;
titleArray[i]=xml.images[i].cn;
painterArray[i]=xml.images[i].en;
dateArray[i]=xml.images[i].misc;
}
}
function beginImage():void {
//load description
infoBox.theArtist.text=painterArray[currPainting];
infoBox.theTitle.text=titleArray[currPainting];
infoBox.theDate.text=dateArray[currPainting];
theImage.scaleX=1;
theImage.scaleY=1;
var imageLoader = new Loader();
//actually loads the URL defined in the image array
imageLoader.load(new URLRequest(imageArray[currPainting]));
//adds a listener for what to do when the image is done loading
imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, imgLoaded);
function imgLoaded(event:Event):void {
//add the image and get the dimensions to center the image
theImage.addChild(imageLoader);
theImage.x = (stage.stageWidth/2) - (imageLoader.content.width / 2);
theImage.y = (stage.stageHeight/2) - (imageLoader.content.height / 2);
finalX = (stage.stageWidth/2) - (imageLoader.content.width * .8 / 2);
finalY = (stage.stageHeight/2) - (imageLoader.content.height * .8 / 2);
//start tween function
easeIn();
}
}
function easeIn():void {
TweenLite.to(theImage, 11.6, {scaleX:.8, scaleY:.8, x:finalX, y:finalY, onComplete:hideStuff});
TweenLite.to(theImage, 1, {alpha:1, overwrite:0});
TweenLite.to(infoBox, 1, {alpha:1});
}
function hideStuff():void {
TweenLite.to(theImage, 1, {alpha:0, onComplete:nextImage});
TweenLite.to(infoBox, 1, {alpha:0});
}
function nextImage():void {
//take out the image that was just displayed
imageArray.splice(currPainting,1);
titleArray.splice(currPainting,1);
painterArray.splice(currPainting,1);
dateArray.splice(currPainting,1);
//remove the picture
theImage.removeChildAt(0);
//start over
if (imageArray.length==0) {
TweenLite.to(theImage, 1, {alpha:0});
TweenLite.to(infoBox, 1, {alpha:0});
TweenLite.to(restartButton, 1, {alpha:0});
TweenLite.to(titleScreen, 1, {alpha:1, delay:1});
TweenLite.to(startButton, 1, {alpha:1, delay:1});
} else {
beginImage();
}
}
返回主菜单后,如何停止 beginImage()(触发 populateArray、easeIn、hideStuff 和 nextImage)?
谢谢。