我想使用無限滾動AS3我在this SO question討論。我正在使用FlashCS5 IDE進行開發。通過Actionscript3加載圖像兩次?
我需要做的絕對最後一件事是在電影的其餘部分加載完畢後從外部加載大背景圖像(「header_bg_vert.jpg」),而不是要求事先加載整個動畫(或者預加載標題動畫)。
我的AS3如下。 「無限循環」通過將兩個相同的無縫圖像端到端地放置兩個副本,然後在將第二個圖像滾動到屏幕之後移動到前方來工作 - 目前,此代碼僅顯示圖像的一個副本。它出什麼問題了?另外,這是完成這個的最好方法嗎?
非常感謝。
stop();
//load the bg image
var request:URLRequest = new URLRequest("header_bg_vert.jpg");
var s1:Loader = new Loader();
var s2:Loader = new Loader();
s1.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loadProgress);
s1.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);
s2.contentLoaderInfo.addEventListener(ProgressEvent.PROGRESS, loadProgress);
s2.contentLoaderInfo.addEventListener(Event.COMPLETE, loadComplete);
function loadProgress(event:ProgressEvent):void {
var percentLoaded:Number = event.bytesLoaded/event.bytesTotal;
percentLoaded = Math.round(percentLoaded * 100);
trace("Loading: "+percentLoaded+"%");
}
function loadComplete(event:Event):void {
trace("Complete");
}
s1.load(request);
s2.load(request);
//The speed of the scroll movement.
var scrollSpeed:uint = 1;
//Originally, this added two instances of the movie clip onto the stage.
//var s1:ScrollBg = new ScrollBg();
//var s2:ScrollBg = new ScrollBg();
addChild(s1);
addChild(s2);
setChildIndex(s1, 0);
setChildIndex(s2, 0);
//This positions the second movieclip next to the first one.
s1.y = 0;
s2.y = s1.height;
//Adds an event listener to the stage.
stage.addEventListener(Event.ENTER_FRAME, moveScroll);
//This function moves both the images to left. If the first and second
//images goes pass the left stage boundary then it gets moved to
//the other side of the stage.
function moveScroll(e:Event):void{
s1.y -= scrollSpeed;
s2.y -= scrollSpeed;
if(s1.y <= -s1.height){
s1.y = s1.height - scrollSpeed;
}else if(s2.y <= -s2.height){
s2.y = s2.height - scrollSpeed;
}
}
您好,先生,贏得了萬億美元的互聯網。這一直在擾亂我至少一個星期。謝謝! – aendrew 2011-02-11 09:14:30