希望在這裏得到一些建議。對於iPad演示文稿的基本導航系統似乎存在問題。幻燈片樣式導航。 addChild&arrays
對於這個例子,我已經將我的庫中的5個頁面添加到數組中。 我想要的效果是,當用戶滑動到下一頁時,它應該: - 使用addChild將下一頁添加到舞臺(視圖外) - 補間當前頁面的視圖,補間下一頁到視圖 - 使用removeChild刪除舊頁面。
這樣做的原因是我會有大量的重動畫頁面,我試圖避免讓他們全都出現在舞臺上,以防止FPS下降。
這是我的代碼到目前爲止。我嘗試了一些東西,例如試圖重新設置currentPage,但沒有運氣。現在拉着我的頭髮幾個小時!
import com.greensock.*;
import com.greensock.easing.*;
import com.greensock.plugins.*;
import flash.events.MouseEvent;
import flash.display.MovieClip;
//touch device swiping
Multitouch.inputMode = MultitouchInputMode.GESTURE;
stage.addEventListener (TransformGestureEvent.GESTURE_SWIPE, fl_SwipeHandler_2);
function fl_SwipeHandler_2(event:TransformGestureEvent):void{
switch(event.offsetX)
{
//swiped right, go back
case 1:
{
prevPage();
break;
}
//swiped left, go forward
case -1:
{
nextPage();
break;
}
}
}
//fill array with movieclip pages from library
var pageArray:Array = [page1, page2, page3, page4, page5];
var currentArray:Number = 0;
//add the first page in the array to the stage as 'currentPage'
var currentPage:MovieClip = new pageArray[currentArray];
addChild(currentPage);
function nextPage(event:TouchEvent):void{
if (currentArray < pageArray.length - 1){
//tween currentPage out to the left, when animation ends removeChild(currentPage);
TweenMax.to(currentPage, 1, {x:-1024,onComplete:removeChild,onCompleteParams:[currentPage]});
//move to the next item in the array
currentArray++
//add the next item in the array to the stage as 'newPage'
var newPage:MovieClip = new pageArray[currentArray]
addChild(newPage);
newPage.x = 1024;
//tween newPage into view
TweenMax.to(newPage, 1, {x:0,onComplete:updatePage});
/*
PROBLEM STARTS HERE:
- if nextPage is executed again, it will try to tween 'currentPage' which has been removed from the stage.
- need to rename/change 'newPage' into 'currentPage' here but don't know how.
*/
}
}
function prevClicked(event:MouseEvent):void{
if (currentArray > 0){
trace("same as nextPage in reverse");
}
}
編輯的問題解決了
因此與aesphere的幫助和一些試驗和錯誤,這似乎是現在的工作。其中一個主要問題是缺少圍繞數組的新的和(),例如:new page1(),new page2()。等等。
Multitouch.inputMode = MultitouchInputMode.GESTURE;
stage.addEventListener(TransformGestureEvent.GESTURE_SWIPE, fl_SwipeHandler_2);
function fl_SwipeHandler_2(event:TransformGestureEvent):void
{
switch (event.offsetX)
{
case 1 :
{
prevPage();
break;
};
case -1 :
{
nextPage();
break;
}
}
};
import com.greensock.*;
import com.greensock.easing.*;
import com.greensock.plugins.*;
import flash.events.MouseEvent;
import flash.display.MovieClip;
var pageArray:Array = [new page1(), new page2(), new page3(), new page4(), new page5()];
var currentPage:Number = 0;
addChild(pageArray[currentPage]);
function nextPage():void
{
if (currentPage < pageArray.length - 1)
{
TweenMax.to(pageArray[currentPage], 1, {x:-1024, onComplete:removeChild, onCompleteParams:[pageArray[currentPage]]});
currentPage++;
pageArray[currentPage].x = 1024;
addChild(pageArray[currentPage]);
TweenMax.to(pageArray[currentPage], 1, {x:0});
}
}
function prevPage():void
{
if (currentPage > 0)
{
TweenMax.to(pageArray[currentPage], 1, {x:1024, onComplete:removeChild, onCompleteParams:[pageArray[currentPage]]});
currentPage--;
pageArray[currentPage].x = -1024;
addChild(pageArray[currentPage]);
TweenMax.to(pageArray[currentPage], 1, {x:0});
}
}
非常感謝您的幫助。我仍然有一些問題,但我只是插入提供的代碼,並不知道如何處理onComplete:updatePage,所以我刪除了,但是當我測試我收到此錯誤:「TypeError:Error#1034 :類型強制失敗:無法將page1 $轉換爲flash.display.DisplayObject。 \t at Examples_fla :: MainTimeline/frame1()「 – user1172903 2012-01-31 05:27:29
什麼是page1,page2,page3等?你怎麼從圖書館裏拿出東西來?是page1的類的名稱還是隻是符號的名稱?如果只是名字,你需要確保你已經在符號屬性中首先選擇了「export for actionscript」,然後而不僅僅是[page1,page2 ...]等,它將變成var pageArray: Array = [new page1(),new page2(),new page3(),new page4(),new page5()]; – Aesphere 2012-01-31 07:38:21