Flash 幻灯片式导航。爱德儿童及;阵列

Flash 幻灯片式导航。爱德儿童及;阵列,flash,actionscript-3,Flash,Actionscript 3,我希望在这里得到一些建议。iPad演示文稿的基本导航系统出现问题 在这个例子中,我的库中有5个页面,我已经将它们添加到一个数组中。 我想要达到的效果是,当用户滑动到下一页时,它应该: -使用addChild(视图外)将下一页添加到后台 -将当前页面移出视图,将下一页转入视图 -使用removeChild删除旧页 原因是我将有大量的页面,带有大量的动画,我试图避免它们同时出现在舞台上,以防止FPS下降 这是到目前为止我的代码。我尝试过一些事情,比如尝试用数组重新设置currentPage,但没有成

我希望在这里得到一些建议。iPad演示文稿的基本导航系统出现问题

在这个例子中,我的库中有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");
    }
}
import com.greensock.*;
导入com.greensock.com;
导入com.greensock.plugins.*;
导入flash.events.MouseEvent;
导入flash.display.MovieClip;
//触摸设备刷卡
Multitouch.inputMode=MultitouchInputMode.手势;
stage.addEventListener(TransformGestureEvent.signature\u SWIPE,fl\u SwipeHandler\u 2);
函数fl_SwipeHandler_2(事件:TransformGestureEvent):无效{
开关(event.offsetX)
{
//向右击,返回
案例1:
{
prevPage();
打破
}
//左击,前进
案例1:
{
下一页();
打破
}
}
}
//使用库中的movieclip页面填充数组
var pageArray:Array=[page1,page2,page3,page4,page5];
var currentArray:Number=0;
//将数组中的第一页作为“currentPage”添加到后台
var currentPage:MovieClip=new pageArray[currentparray];
addChild(当前页面);
函数下一页(事件:TouchEvent):无效{
如果(currentArray0){
跟踪(“与下一页相反的内容相同”);
}
}
编辑问题已解决 因此,在aesphere和一些尝试和错误的帮助下,它似乎正在发挥作用。主要问题之一是阵列周围缺少new(),例如:new page1()、new page2()。等等

multi-touch.inputMode=multi-touchinputmode.signature;
stage.addEventListener(TransformGestureEvent.signature\u SWIPE,fl\u SwipeHandler\u 2);
函数fl_SwipeHandler_2(事件:TransformGestureEvent):无效
{
开关(event.offsetX)
{
案例1:
{
prevPage();
打破
};
案例1:
{
下一页();
打破
}
}
};
导入com.greensock.*;
导入com.greensock.com;
导入com.greensock.plugins.*;
导入flash.events.MouseEvent;
导入flash.display.MovieClip;
var pageArray:Array=[new page1()、new page2()、new page3()、new page4()、new page5()];
var currentPage:编号=0;
addChild(pageArray[currentPage]);
函数nextPage():void
{
如果(当前页面0)
{
TweenMax.to(pageArray[currentPage],1,{x:1024,onComplete:removeChild,onCompleteParams:[pageArray[currentPage]]});
当前页--;
pageArray[currentPage].x=-1024;
addChild(pageArray[currentPage]);
TweenMax.to(pageArray[currentPage],1,{x:0});
}
}

页面之间的简单导航实际上应该只使用一个变量来跟踪当前页面。您已经描述了您想要做什么,但是您已经使事情变得比您的代码需要的更复杂

因为您有一个跟踪当前页面的计数器变量,所以您应该只使用已经需要添加child和删除child的页面数组,这样您就有了一个控制点,其中currentPage始终引用页面数组中stage上的当前movieclip

因此,从您的代码:

import com.greensock.*;
import com.greensock.easing.*;
import com.greensock.plugins.*;
import flash.events.MouseEvent;
import flash.display.MovieClip;

//I like to setup the required assets and variables first, then put everything else below:
//fill array with movieclip pages from library
var pageArray:Array = [page1, page2, page3, page4, page5];
var currentPage:Number = 0;

//Next we add the first page to the stage
addChild(pageArray[currentPage]);

//Now we add the listeners for the functionality
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;
    }
}

//The handlers for the swiping gestures for switch pages
function nextPage(event:TouchEvent):void
{
    //First check if we have a next page or not.
    if (currentPage < pageArray.length - 1){
        //So, we want to move to the next page, we first Tween the current page off to left

        TweenMax.to(pageArray[currentPage], 1, {x:-1024, onComplete:removeChild, onCompleteParams:[pageArray[currentPage]]});
        //Once the Tween starts,increment the page counter, set the starting xpos, addChild
        //and then tween that into place.
        currentPage++;
        pageArray[currentPage].x = 1024;
        addChild(pageArray[currentPage]);
        //Tweening into place then calls the updatePage when tween is complete.
        TweenMax.to(pageArray[currentPage], 1, {x:0, onComplete:updatePage});
    }

}

function prevPage(event:TouchEvent):void
{
    trace('pretty much nextPage but decrementing currentPage plus a check against 0');
}
import com.greensock.*;
导入com.greensock.com;
导入com.greensock.plugins.*;
导入flash.events.MouseEvent;
导入flash.display.MovieClip;
//我喜欢先设置所需的资产和变量,然后将所有其他内容放在下面:
//使用库中的movieclip页面填充数组
var pageArray:Array=[page1,page2,page3,page4,page5];
var currentPage:编号=0;
//接下来,我们将第一页添加到舞台
addChild(pageArray[currentPage]);
//现在,我们为该功能添加侦听器
Multitouch.inputMode=MultitouchInputMode.手势;
stage.addEventListener(TransformGestureEvent.signature\u SWIPE,fl\u SwipeHandler\u 2);
函数fl_SwipeHandler_2(事件:TransformGestureEvent):无效{
开关(event.offsetX)
{
//向右击,返回
案例1:
prevPage();
布雷亚
import com.greensock.*;
import com.greensock.easing.*;
import com.greensock.plugins.*;
import flash.events.MouseEvent;
import flash.display.MovieClip;

//I like to setup the required assets and variables first, then put everything else below:
//fill array with movieclip pages from library
var pageArray:Array = [page1, page2, page3, page4, page5];
var currentPage:Number = 0;

//Next we add the first page to the stage
addChild(pageArray[currentPage]);

//Now we add the listeners for the functionality
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;
    }
}

//The handlers for the swiping gestures for switch pages
function nextPage(event:TouchEvent):void
{
    //First check if we have a next page or not.
    if (currentPage < pageArray.length - 1){
        //So, we want to move to the next page, we first Tween the current page off to left

        TweenMax.to(pageArray[currentPage], 1, {x:-1024, onComplete:removeChild, onCompleteParams:[pageArray[currentPage]]});
        //Once the Tween starts,increment the page counter, set the starting xpos, addChild
        //and then tween that into place.
        currentPage++;
        pageArray[currentPage].x = 1024;
        addChild(pageArray[currentPage]);
        //Tweening into place then calls the updatePage when tween is complete.
        TweenMax.to(pageArray[currentPage], 1, {x:0, onComplete:updatePage});
    }

}

function prevPage(event:TouchEvent):void
{
    trace('pretty much nextPage but decrementing currentPage plus a check against 0');
}