0
votes

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);
}
3
this.numChildren - 1 will do this, if u have 6 objects, it will make it the 5th one. if u want it to be at the very top all the time, just manually put in 0 as the index number. so setChildIndex(cont, 0);tailedmouse
doesnt word either :Suser2397976
is the image loaded ? you see it ?Ivan Chernykh
yes! the only problem is the index, the rest is gooduser2397976

3 Answers

1
votes

You need to set the child index of e.currentTarget, not cont.

setChildIndex(DisplayObject(e.currentTarget), this.numChildren - 1);
0
votes

Also try this setChildIndex(currentObject, getChildIndex(myObject)-1)

0
votes

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