Reputation: 7
I'm making a book with a page flipping effect (I only have it flipping the right page until now), and I'm having a problem with the index, because the page that I flip doesnt stay on top of the others.
I tried writing setChildIndex(cont, this.numChildren -1) but it is not working!
import fl.transitions.Tween;
import fl.transitions.easing.*;
import fl.transitions.TweenEvent;
import flash.display.Sprite;
var cont : DisplayObject;
var imgLoader : Loader;
for (var i:int=0; i<=4; i++){
imgLoader = new Loader();
imgLoader.contentLoaderInfo.addEventListener(Event.INIT, onLoadJPEG);
imgLoader.load(new URLRequest(""+i+".png"));
}
function onLoadJPEG (e : Event) : void {
cont = e.target.loader;
cont.x =300;
cont.y =65;
cont.width = 286/2;
cont.height = 406/2;
addChild(cont);
cont.addEventListener(MouseEvent.MOUSE_UP, FlipPage);
}
function FlipPage(e:MouseEvent):void{
setChildIndex(cont, this.numChildren -1);
var myTween:Tween = new Tween(e.currentTarget, "rotationY", Regular.easeInOut,0, 180, 1, true);
}
Upvotes: 0
Views: 1031
Reputation: 92
The spriteorder will of course be wrong. Easiest way to put something on top is addChild for that you want have one top.
addChild(a); //indexorder a
addChild(b); //indexorder ba
addChild(c); //indexorder cba
addChild(a); //indexorder acb
Upvotes: 0
Reputation: 1334
Also try this setChildIndex(currentObject, getChildIndex(myObject)-1)
Upvotes: 0
Reputation: 5459
You need to set the child index of e.currentTarget
, not cont
.
setChildIndex(DisplayObject(e.currentTarget), this.numChildren - 1);
Upvotes: 1