A Flash Developer Resource Site

Results 1 to 2 of 2

Thread: My "other" issue - falling behind

  1. #1
    Join Date
    Oct 2003

    My "other" issue - falling behind

    Quick recap if you haven't seen the other thread:

    Have doors that open when clicked and close when clicked. When you click one it uses getNextHighestDepth and swapDepths to come to the forefront so the door doesn't open "under" the neighboring door. I've also set it up so that you can open each set of doors (left and right) together but if you click any other door the originally open door (or doors if you've opened both) close and then the new ones open.

    Some odd things happen though. If you open door 3 (a left door) for example, then door four (the right counterpart) SOMETIMES door 3 drops behind the artwork for door 2.

    Only sometimes.

    I've gone so far as to retrieve the depth of the clicked door (after getting the next highest depth), storing that as a number variable, then adding (++) to that variable and swapping depths with this new incremented variable thinking that might help (so the second door is not just swapping with the first clicked door, sending it down to where the second door was in case it was lower than others).

    See the screen grab for an idea of the proximity and how the doors will open under neighboring doors.

    Convoluted code which doesn't appear to be working is:

    Actionscript Code:
    nextDepth = this.getNextHighestDepth();
    incrementalDepth = nextDepth++;
    holdDepth = this.getDepth();

    Hold depth is my attempt to "lock" the mc at it's new depth until that depth increments.

    Oddly, my traces are all "1"???

    I'm pulling my hair out over this - which is funny 'cuz I haven't got any hair.....

    Screenshot of UI here: grab.jpg

    Something I DID manage to accomplish (in case it helps you explain to me what I'm doing wrong)....when you open the cupboards there are items inside that you can drag out and drop into the grocery bags in the front there. They are on a layer under the cupboard doors but when you click to start the drag they jump to the next highest level so that you don't drag them under the other doors. If you "miss" it snaps back where you found it AND drops back to it's original depth (so it falls behind the doors when they close).

    I can't thank you enough for your time and thoughts on this. It's driving me nuts (as you can tell from the desperate ActionScript and the novel-length thread).

  2. #2
    Prid - Outing Nig 13's Avatar
    Join Date
    Jul 2006
    Sorry for late answer, I fixed the problem, however. The problem is that each Door is a Movieclip, and each movieclip has its own depths, so when you're saying this:

    var nextDepth:Number = this.getNextHighestDepth();
    you are actually referring to the next highest available depht level INSIDE that particular movieclip, which should be for each movieclip, 0, as the first available next highest depth, and you would make all of those that, so when some else door is at Depth 0, and you use swapDepths on any other door and its Depth is also set as 0, it swaps its Depth with the object assigned on Depth 0, making the depth of the currently clicked door, switch places with the previously pressed door (a bit confusing, but I hope you get what I mean - hence the name, swapDepths).

    Simply, on all doors, change this to _root:

    var nextDepth:Number = _root.getNextHighestDepth();
    which would then find the next highest available depth on the _root level, so if you set its depth to 0, and then click on another door, that door would then find the the next highest available depth on the _root level (rather than on its own level), making the next available highest depth, 1

    In short, from the file you posted on the other forum, on all the doors, change this to _root

    Hope this helps


    To further explain swapDepths, all the Movieclips placed on the Stage manually have a depth somewhere down at -16000, really low, right? So, when you swap the depths of that manually placed Movieclip with depth of -16000 to 0, its depth is then set to 0. Then, if you swap another manually created Movieclip with a depth of -16001, to the depth 0, you then make the first Movieclip's depth change places with the other movieclip, making the first movieclip's depth -16001, and the newly depth swapped Movieclip's depth, 0
    Last edited by Nig 13; 03-16-2012 at 04:38 PM.
    I am back, guys ... and finally 18 :P


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Click Here to Expand Forum to Full Width

HTML5 Development Center