3 Replies Latest reply on Nov 15, 2007 1:51 PM by Avix_Turch

    Drag and Drop on top of each other

    YTCollege Level 1
      I am creating a drag and drop game to show how a basic surgical tray is set up. When setting a tray up, the items must be placed in a certain order and some things are placed on top of each other. My problem is that when I place something on top of another it is fine until I pick up another object then the second object goes behind the first object. Example: Object B is place on top of Object A. When Object C is clicked on, then object B goes behind object A. How can I stop the images from shifting? I am using swapdepths and getNextHighestDepth. Below is my code:

      Bowl_MC.onPress = function():Void {
      reply_txt.text = "";
      xstart = this._x ;
      ystart = this._y ;

      Bowl_MC.onRelease = function():Void {
      if (eval(this._droptarget) == target_bowl_mc) {
      reply_txt.text = "You got it!";
      this.enabled = false;
      this._x = target_bowl_mc._x;
      this._y = target_bowl_mc._y;
      } else {
      reply_txt.text = "No, keep trying!";
      this._x = xstart;
      this._y = ystart;

      This is just a section of the code. Each piece of code is the same for each movable object on the screen. Thanks in advance for any help.
        • 1. Re: Drag and Drop on top of each other
          kglad Adobe Community Professional & MVP
          oops, don't use this.getNextHighestDepth(). use this._parent.getNextHighestDepth(), if all your objects have the same _parent movieclip.
          • 2. Re: Drag and Drop on top of each other
            YTCollege Level 1
            Thanks for writing back. I tried your advice and it still does the same thing. All of my objects are separate movie clips but they are all on the same layer on the root level. I tried to put each object on separate layers but it still did the same. It seems that I read before that it depends on the order that you import the pictures as to what depth the pictures will be. Has anyone ever heard this? I have no other code in my project. The code that is posted above is copied 25 times and the names of the movie clips are changed.
            • 3. Re: Drag and Drop on top of each other
              getNextHighestDepth() doesn't work unless you are attaching a movieClip. The best way i know how to do this is to set up a variable on your main timeline such as:

              var currentDepth:Number = 200;

              Then in your code when they drop the item, place this code:


              this will make whatever item you drop be on top at all times. Now if you want items to go beneath others or on top of others in a certain way no matter how they drop it, I would suggest defining each items depth.

              (if item A's instance name is "itemA" and so on)

              var item_A_Var:Number = 5;
              itemB.swapDepths(item_A_Var - 1);

              this will make Item B go under Item A.