7 Replies Latest reply on May 28, 2006 11:01 PM by matecito

    Draggin' and Droppin...

    matecito
      Warning: I'm still learning! If there are better ways to do this from the ground up - set me straight!

      I built a chess board in flash. Each square is represented by an array address...

      I am trying to drag and drop pieces. They drag - but they don't drop. Can someone give me a clue? Is this where I should be using EventListeners instead?
        • 1. Re: Draggin' and Droppin...
          NSurveyor Level 2
          You aren't dragging the chess square, but the created piece. Therefore, you aren't "releasing" the chess square. Here's a work around:

          • 2. Re: Draggin' and Droppin...
            NSurveyor Level 2
            It just occurred to me that you can use:

            arr[0][0].onRelease = arr[0][0].onReleaseOutside = function(){stopDrag()};

            onRelease only happens when you press on something, and then release still on top of it. onReleaseOutside is same, but when you move the mouse off the clip before releasing.
            • 3. Re: Draggin' and Droppin...
              matecito Level 1
              Well,

              I tried both of these suggestions and neither one worked. The new piece follows my mouse around - never letting me drop it.

              But thanks for the attempt. Maybe you need more info?

              These are buttons... would that make any difference?
              • 4. Re: Draggin' and Droppin...
                NSurveyor Level 2
                Use _root.getNextHighestDepth(); inside the onPress handler. Also, if you drag again on the blackrooklight clip, more pieces are going to be created but only the first one will be dragged as you aren't using a unique name. Try:

                _global.draggable = _root.attachMovie("gbRook","gbRook"+_root.getNextHighestDepth(),_root.getNextHighestDepth ());
                • 5. Re: Draggin' and Droppin...
                  NSurveyor Level 2
                  By the way, use
                  arr[0][0].onRelease = arr[0][0].onReleaseOutside = function(){stopDrag()}; as well
                  • 6. Re: Draggin' and Droppin...
                    matecito Level 1
                    Mmmkay... that works. Can you email your years of Flash experience in an attachment?

                    I hope I don't wear out my welcome - but here's the next hurdle.

                    var arr:Array = new Array();
                    arr[0] = new Array();

                    arr[0][0] = this.attachMovie("oBlackRookLight", "oBlackRookLight", this.getNextHighestDepth());
                    arr[0][0].onPress = function(){
                    _global.draggable = _root.attachMovie("gbRook","gbRook"+_root.getNextHighestDepth(),_root.getNextHighestDepth ());
                    startDrag(_global.draggable);
                    }

                    arr[0][0].onRelease = arr[0][0].onReleaseOutside = function(){
                    stopDrag();
                    _root.removeMovieClip(_global.draggable);
                    }

                    The last instruction doesn't work... I would like to remove what I dragged as soon as it lands (I am going to replace it with another clip instead).

                    Kinda confusing how Flash references are handled... to say the least.

                    Oh - one other question while I'm at it...

                    The way I am going about this - I am going to attach all these movies and create these onPress / onRelease one by one.

                    i.e. - like this...

                    -------------------------

                    var arr:Array = new Array();
                    arr[0] = new Array();

                    arr[0][0] = this.attachMovie("oBlackRookLight", "oBlackRookLight", this.getNextHighestDepth());
                    arr[0][0].onPress = function(){
                    _global.draggable = _root.attachMovie("gbRook","gbRook"+_root.getNextHighestDepth(),_root.getNextHighestDepth ());
                    startDrag(_global.draggable);
                    }

                    arr[0][0].onRelease = arr[0][0].onReleaseOutside = function(){
                    stopDrag();
                    _root.removeMovieClip(_global.draggable);
                    }

                    arr[0][1] = this.attachMovie("oBlackKnightDark","oBlackKnightDark", this.getNextHighestDepth());
                    arr[0][1].onPress = function(){
                    _global.draggable = _root.attachMovie("gbKnight","gbKnight"+_root.getNextHighestDepth(),_root.getNextHighestD epth());
                    startDrag(_global.draggable);
                    }

                    arr[0][1].onRelease = arr[0][0].onReleaseOutside = function(){
                    stopDrag();
                    _root.removeMovieClip(_global.draggable);
                    }

                    arr[0][2] = this.attachMovie("oBlackBishopLight", "oBlackBishopLight", this.getNextHighestDepth());
                    arr[0][2].onPress = function(){
                    _global.draggable = _root.attachMovie("gbBishop","gbBishop"+_root.getNextHighestDepth(),_root.getNextHighestD epth());
                    startDrag(_global.draggable);
                    }

                    arr[0][2].onRelease = arr[0][2].onReleaseOutside = function(){
                    stopDrag();
                    _root.removeMovieClip(_global.draggable);
                    }

                    -------------------

                    Is there any way I could do this via a loop?

                    i.e.

                    for(b=0;b<=7;b++){
                    for (v=0;v<=7;v++){
                    :::::SET UP EACH PIECE HERE:::
                    }
                    }

                    The more questions you ask... the closer you get to a free delivered Pizza.... with all the toppings... any night you want. Seriously!
                    • 7. Re: Draggin' and Droppin...
                      matecito Level 1
                      Ok...

                      I figured out the reference bit....

                      removeMovieClip(_global.draggable);

                      (no _root needed)

                      still curious if I can do all this from within a loop though... would be so much more efficient.