2
除了當我點擊向前或向後通過我的圖像時,我幾乎都會按照我想要的方式使用這個東西,一旦碰到數組長度,下一張圖片就不會顯示。當我添加checkImage()方法時,這只是一個問題。任何人都可以看到我錯了什麼?gallery last image fix
修復**
package
{
import flash.display.MovieClip;
import flash.display.Sprite;
import flash.display.DisplayObject;
import flash.events.Event;
import flash.events.MouseEvent;
import com.greensock.TweenMax;
import com.greensock.layout.*;
import com.greensock.loading.LoaderMax;
import com.greensock.loading.XMLLoader;
import com.greensock.loading.ImageLoader;
import com.greensock.events.LoaderEvent;
import com.greensock.loading.display.ContentDisplay;
import com.greensock.loading.data.XMLLoaderVars;
public class Main extends MovieClip
{
public var imgHolder:MovieClip;
private var ls:LiquidStage;
private var la:LiquidArea;
private var xml:XMLLoader;
private var index:int = 0;
private var images:Array;
public function Main()
{
arrowRight.alpha = arrowLeft.alpha = .5;
xmlLoader();
}
private function xmlLoader():void
{
LoaderMax.activate([ImageLoader]);
xml = new XMLLoader("assets/data.xml", new XMLLoaderVars()
.name("loader")
.estimatedBytes(600000)
.onComplete(xmlLoaded)
.onProgress(loadProgress));
xml.load();
}
private function xmlLoaded(e:LoaderEvent):void
{
trace("Loaded");
arrowListeners();
showImage(index);
}
private function loadProgress(event:LoaderEvent):void
{
progressMC.progressBar.scaleX = event.target.progress;
}
private function showImage(index:int):void
{
ls = new LiquidStage(this.stage, 1024, 768, 1024, 768);
la = new LiquidArea(imgHolder, 0, 0, 1024, 768);
images = LoaderMax.getContent("loader");
imgHolder.addChild(images[index]);
TweenMax.from(images[index], 1, {alpha:0});
la.attach(images[index], {scaleMode:ScaleMode.PROPORTIONAL_OUTSIDE, crop:true});
}
// BUTTON FUNCTIONS
private function arrowListeners():void
{
arrowRight.addEventListener(MouseEvent.ROLL_OVER, rollOverArrowHandler, false, 0, true);
arrowRight.addEventListener(MouseEvent.ROLL_OUT, rollOutArrowHandler, false, 0, true);
arrowRight.addEventListener(MouseEvent.CLICK, showNext);
arrowLeft.addEventListener(MouseEvent.ROLL_OVER, rollOverArrowHandler, false, 0, true);
arrowLeft.addEventListener(MouseEvent.ROLL_OUT, rollOutArrowHandler, false, 0, true);
arrowLeft.addEventListener(MouseEvent.CLICK, showPrev);
}
private function rollOverArrowHandler(e:MouseEvent):void
{
TweenMax.to(e.currentTarget, 0.5, {alpha:1});
}
private function rollOutArrowHandler(e:MouseEvent):void
{
TweenMax.to(e.currentTarget, 0.5, {alpha:.5});
}
// CLICK LISTENERS
private function showNext(e:MouseEvent):void
{
index++
if (index > images.length - 1)
{
index = 0;
}
showImage(index);
}
private function showPrev(e:MouseEvent):void
{
index--
if (index < 0)
{
index = images.length - 1;
}
showImage(index);
}
}
}
感謝您的回覆。我試圖添加不同的變量來解決param衝突和其他問題列表,但現在出現錯誤「TypeError:Error#1034:Type Coercion failed:can not convert flash.display :: Shape @ 4e18aa11 to flash.display.Sprite 「。我不知道任何其他方式來擺脫舊的形象,我得到了什麼。你能想到另一種安全的方式來刪除以前的圖像? – Nerdysyntax 2011-12-26 16:09:23
不完全確定代碼應該做什麼..但我不知道你是否可以在開始時加載所有圖像並循環播放它們。爲什麼加載並重新加載它們? – ethrbunny 2011-12-26 16:15:11
哦,是的,我新來這個,所以我的代碼可能看起來不穩定。我只是試圖爲瀏覽器縮放設置圖像庫的下一個和上一個按鈕。我想最初我沒有checkImage函數循環,它工作正常,但我想那裏需要一些類型的垃圾收集。我應該刪除checkImage()? – Nerdysyntax 2011-12-26 16:23:32