3 Replies Latest reply: Sep 14, 2010 12:08 PM by BrianatArena RSS

    setting child index from within array

    BrianatArena Community Member

      Here's what I'm trying to accomplish: I have as3 script that successfully displays an array of MovieClips, the MCs have variable xy positions, and in some cases they overlap each other. I have a function within the array that I can't quite figure out. Here's what I'd like the function to do: When the cursor rolls over a particular MC displayed by the array, I'd like that MC to be brought to the front of the others. This is my script:

       

      var myArray:Array = new Array();
      for(var i:int=0; i<8; i++) {
      myArray[i]= new myImage();
      addChild(myArray[i]);
      myArray[i].x = 180*i;
      myArray[i].y = 330;

      myArray[i].addEventListener(MouseEvent.ROLL_OVER , overlap);

       

      function overlap (event:MouseEvent):void

      {
      trace('function triggered on image ' + i);

      // this trace always returns "function triggered on image 8", even if I click on image 1-7

      setChildIndex(thumbsArray[i], numChildren - 1); //my best attempt at trying to bring it to the front
      }

      }
      }

       

      it generates this in the output panel on each rollover:

       

      function triggered on image 8

      TypeError: Error #2007: Parameter child must be non-null.
          at flash.display::DisplayObjectContainer/setChildIndex()
          at Function/<anonymous>()

       

      My best guess is that I'm not properly identifying the variable i in the function, advice is appreciated.