I’m trying to work on a presentation/slideshow, where I will have to insert and remove pages quite often. I had the idea that I could just change the array by setting it from each movie clip (each movieclip is a slide or page).
this is the script on my root
//array setup
var pageArray:Array = [new page1(), new page2(), new page3(), new page4(), new page5];**
var currentPage:Number = 0;
addChild(pageArray[currentPage]);
//go to next page function
function nextPage():void
{
if (currentPage < pageArray.length - 1)
{
TweenMax.to(pageArray[currentPage], 1, {cacheAsBitmap:true, x:-1024, onComplete:removeChild, onCompleteParams:[pageArray[currentPage]]});
currentPage++;
pageArray[currentPage].x = 1024;
addChild(pageArray[currentPage]);
TweenMax.to(pageArray[currentPage], 1, {cacheAsBitmap:true, x:0, onComplete:pageArray[currentPage].startAnimation});
}
}
//go to prev page function
function prevPage():void
{
if (currentPage > 0)
{
TweenMax.to(pageArray[currentPage], 1, {cacheAsBitmap:true, x:1024, onComplete:removeChild, onCompleteParams:[pageArray[currentPage]]});
currentPage--;
pageArray[currentPage].x = -1024;
addChild(pageArray[currentPage]);
TweenMax.to(pageArray[currentPage], 1, {cacheAsBitmap:true, x:0, onComplete:pageArray[currentPage].startAnimation});
}
}
Then on for example the movieclip page3, I have this:
import com.greensock.*;
import flash.events.MouseEvent;
//startAnimation is called when the tween finishes on the root via onComplete
function startAnimation():void{
MovieClip(root).pageArray = [new page1(), new page2(), new page3(), **new extra1(), new extra2(),** new page4(), new page5];
//i have tried to insert 2 new pages "extra1" and "extra2"
}
/*
addEventListener(Event.REMOVED_FROM_STAGE, onRemovedFromStage);
function onRemovedFromStage(event:Event):void{
trace("removed");
}
*/
I hoped it would just take the new pageArray I’ve set and continue on like usual but it seems to be causing a few issues. pageArray[currentPage] is no longer recognised for that slide and I also get a “ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.” error.
I understand there is a correct way to do this with array splicing to insert the new items but I have multiple options that need to be added/removed so adding or removing based on index will be difficult later.