# AS3 help with setChildIndex and objects disappearing

**URL:** <https://forum.kirupa.com/t/as3-help-with-setchildindex-and-objects-disappearing/318719>\
**Category:** flash\
**Created:** [January 28, 2011, 1:03am UTC](https://forum.kirupa.com/t/as3-help-with-setchildindex-and-objects-disappearing/318719 "2011-01-28T01:03:08Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![weatherdown](https://avatars.discourse-cdn.com/v4/letter/w/f475e1/32.png) [@weatherdown](https://forum.kirupa.com/u/weatherdown)\
**Post date:** [January 28, 2011, 1:03am UTC](https://forum.kirupa.com/t/as3-help-with-setchildindex-and-objects-disappearing/318719/1 "2011-01-28T01:03:08Z")

</div>

Description of Project:

I am building a prototype of an experimental website design where the pages fly at you as if they were on a zip line of sorts. The problem I am having is the when “page 1” (the page on the first layer) is sent to the back it appears above “page 5” (the page on the last layer). When I try to use setChildIndex to send page 1 to the back, for some reason it makes my page 1 disappear until the next time the timeline starts over.

I have included my code and demos of my project.

Demos:

swf without actionscript: [http://dustinnaquin.com/swfs/prototype\_no\_actions.swf](http://dustinnaquin.com/swfs/prototype_no_actions.swf)  
swf with actionscript: [http://dustinnaquin.com/swfs/prototype\_actions.swf](http://dustinnaquin.com/swfs/prototype_actions.swf)

```auto
import flash.display.DisplayObject;
import flash.events.Event;

var page1:DisplayObject = this.getChildByName("page_1");
var page2:DisplayObject = this.getChildByName("page_2");
var page3:DisplayObject = this.getChildByName("page_3");
var page4:DisplayObject = this.getChildByName("page_4");
var page5:DisplayObject = this.getChildByName("page_5");

addEventListener(Event.ENTER_FRAME, onEnterFrame);

function onEnterFrame(e:Event):void{
    if(e.currentTarget.currentLabel == "swap1") this.setChildIndex(page1, this.numChildren -1);
    if(e.currentTarget.currentLabel == "swap2") this.setChildIndex(page2, this.numChildren -1);
    if(e.currentTarget.currentLabel == "swap3") this.setChildIndex(page3, this.numChildren -1);
    if(e.currentTarget.currentLabel == "swap4") this.setChildIndex(page4, this.numChildren -1);
    if(e.currentTarget.currentLabel == "swap5") this.setChildIndex(page5, this.numChildren -1);
}

```

Any help would be appreciated!!
