# Trying to swap the index of Children on click

**URL:** <https://forum.kirupa.com/t/trying-to-swap-the-index-of-children-on-click/282304>\
**Category:** Uncategorized\
**Created:** [February 20, 2009, 1:28am UTC](https://forum.kirupa.com/t/trying-to-swap-the-index-of-children-on-click/282304 "2009-02-20T01:28:59Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![wildlettuce](https://avatars.discourse-cdn.com/v4/letter/w/cdc98d/32.png) [@wildlettuce](https://forum.kirupa.com/u/wildlettuce)\
**Post date:** [February 20, 2009, 1:28am UTC](https://forum.kirupa.com/t/trying-to-swap-the-index-of-children-on-click/282304/1 "2009-02-20T01:28:59Z")

</div>

I have a feeling I might be going about this all wrong. I have 3 objects (mask\_cat, mask\_dog, mask\_sea\_monster)on the stage and I want the user to be able to move them independently with the ol’ click and drag. This is what I have:

```auto
 package {
    import flash.display.Sprite;
    import flash.display.MovieClip;
    import flash.events.MouseEvent;
    import flash.geom.Rectangle;

    public class maskGuys extends MovieClip {
        private var bg1:Sprite;
        private var mask_cat:MovieClip;
        private var mask_dog:MovieClip;
        private var mask_sea_monster:MovieClip;
        
        
        public function maskGuys() {
            init();
        }
        private function init():void {
            var bg1:Background1 = new Background1();
            addChild(bg1);
            bg1.x = 125;
            bg1.y = 40;

            mask_cat = new MaskCat();
            addChild(mask_cat);
            mask_cat.x = 50;
            mask_cat.y = 30;
            mask_cat.addEventListener(MouseEvent.MOUSE_DOWN, onClickDown);
            mask_cat.addEventListener(MouseEvent.CLICK, clickswap);
            
            mask_dog = new MaskDog();
            addChild(mask_dog);
            mask_dog.x = 10;
            mask_dog.y = 175;
            mask_dog.addEventListener(MouseEvent.MOUSE_DOWN, onClickDown);
            mask_dog.addEventListener(MouseEvent.CLICK, clickswap);

            mask_sea_monster = new MaskSeaMonster();
            addChild(mask_sea_monster);
            mask_sea_monster.x = 450;
            mask_sea_monster.y = 100;
            mask_sea_monster.addEventListener(MouseEvent.MOUSE_DOWN, onClickDown);
            mask_sea_monster.addEventListener(MouseEvent.CLICK, clickswap);
        }
        function onClickDown(event:MouseEvent):void {
            stage.addEventListener(MouseEvent.MOUSE_UP, onClickUp);
            mask_cat.startDrag(false, new Rectangle(10, 10, 500, 200));
            mask_dog.startDrag(false, new Rectangle(10, 10, 500, 200));
            mask_sea_monster.startDrag(false, new Rectangle(10, 10, 500, 200));
        }
        function onClickUp(event:MouseEvent):void {
            stage.removeEventListener(MouseEvent.MOUSE_UP, onClickUp);
            mask_cat.stopDrag();
            mask_dog.stopDrag();
            mask_sea_monster.stopDrag();
        }
        function clickswap(event:MouseEvent) {
            setChildIndex(MovieClip(event.currentTarget),numChildren-1);
        }
    }
}

```

So far only the , sea\_monster moves. The odd thing is the sea\_monster moves when I click on the dog or the cat also, but not if I click anywhere else.

Any ideas?
