3 Replies Latest reply on Jun 23, 2009 12:21 PM by joegeiger

    Setting z-depth order of buttons

    joegeiger

      I have tried repeatedly to take the examples in setChildIndex and instead of using sprites I want to control the order of 2 buttons on the stage so that when I roll over one of the buttons it comes to the top.

       

      Here is the code I have so far which is from the example given in the on-line documentation:

       

      var container:Sprite = new Sprite();
      addChild(container);


      newReleases_mc.addEventListener(MouseEvent.MOUSE_OVER, clicked);
      topRated_mc.addEventListener(MouseEvent.MOUSE_OVER, clicked);


      container.addChild(newReleases_mc);
      container.addChild(topRated_mc);
      addChild(container);

      function clicked(event:MouseEvent):void {
          var circle:Sprite = Sprite(event.target);
          var topPosition:uint = container.numChildren - 1;
          container.setChildIndex(circle, topPosition);
      }

       

      When I run this and roll over the objects on the screen it gives me this error:


      ArgumentError: Error #2025: The supplied DisplayObject must be a child of the caller.
          at flash.display::DisplayObjectContainer/setChildIndex()
          at asndasd_fla::MainTimeline/clicked()

       

      What am I doing wrong?