2 Replies Latest reply on Sep 15, 2007 6:54 AM by clbeech

    HELP - serious swapDepths() bug

    crazygringo Level 1

      I'm trying to create a basic "windowing" setup in a Flash app. I have lots of separate "window" symbols, and when I click on each one I want it to come to the front, overlapping other windows.

      So I write something like

      myWindow.onPress = function() {
      if (this.getDepth() != this._parent.getNextHighestDepth() - 1) {
      this.swapDepths(this._parent.getNextHighestDepth() - 1);

      If there are only two or three windows it works. But if there are four or five, then sometimes the window I click on doesn't rise to the top--*another* window rises to the top.

      I discovered I could get a partial workaround by looping:

      myWindow.onPress = function() {
      while (this.getDepth() != this._parent.getNextHighestDepth() - 1) {
      this.swapDepths(this._parent.getNextHighestDepth() );

      Note, crucially, there is no "- 1" on the second getNextHighestDepth(). If I keep it, the program hangs. But if I always increment the depth, then *eventually* the window I click on makes it to the top, even if it has to loop a couple of times.

      Unfortunately, it messes up the order of other windows on the way.

      This seems to me to be a clear, strong bug in Flash. I'm using CS3 and AS 2.0.

      Has anybody encountered this? Any advice or solid workarounds? I'm using depth levels from 1 upwards, and they're all MovieClips created at runtime. And I'm not using the timeline or anything...

        • 1. Re: HELP - serious swapDepths() bug
          kglad Adobe Community Professional & MVP
          there are no problems with swapDepths() that i know about. however, getNextHighestDepth() is problematic when it is used in a fla that includes several v2 components.
          • 2. Re: HELP - serious swapDepths() bug
            clbeech Level 3
            Kgald's right. If your using getNextHighestDepth(), you must not have to worry about replacing anything at other depths above your starting point, therefore why don't you use a simple counter and increament to the next depth. on the main timeline delcare a variable, then in each 'button' on handler increament the depth when pressed to bring the window's focus to the top.

            var depth:Number = 0;

            myWindow.onPress = function() {