Hello,

I posted this on the newbie's list and didn't get a response, so I
figured I would try here. Sorry for the double post for those of you who
watch both lists.

I have a drag and drop and have an issue. When I roll over one of the
other pieces and click the piece stays instead of jumping back to its
original location.  It is not snapping to the target -- I removed the
target from the stage when the first piece snapped into place.  It just
gets caught behind the other drag piece and when I click the program
gets completely confused.

Is there a way to swap depths when a piece is dragged over another piece
so that the drag piece is always on top?   I know how to do this from a
button, but I don't know how to activate this event when a piece touches
another piece.

Below is my code, in case you would like a peak. Any suggestions you
have are welcome. I am very much a newbie.

Thanks,
Susan

__________________________________________________________

import mx.utils.Delegate;
//myButton.onRelease = Delegate.create(this, traceMe);
match = 0;
function dragMe() {
        this.startDrag();
        trace(this);
}
function activateDrag() {
        piece_mc1.onPress = Delegate.create(piece_mc1, dragMe);
        piece_mc2.onPress = Delegate.create(piece_mc2, dragMe);
        piece_mc3.onPress = Delegate.create(piece_mc3, dragMe);
        piece_mc4.onPress = Delegate.create(piece_mc4, dragMe);
}
function checkIfMatching(dragPiece, dragTarget, originalLocation) {
        trace("dragPiece = "+dragPiece+" dragTarget = "+dragTarget+"
originalLocation = "+originalLocation);
        dragPiece.stopDrag();
        drop = 0;
        trace(dragPiece.hitTest(target_mc1));
        trace("target_mc1._x = "+target_mc1._x);
        if (dragPiece.hitTest(dragTarget)) {
                trace("*************MATCH*************");
                match++;
                trace(match);
                dragPiece._x = dragTarget._x;
                dragPiece._y = dragTarget._y;
                trace("stop x= "+dragTarget._x+" y = "+dragTarget._y);
                trace(dragTarget+" x= "+dragTarget._x+" y =
"+dragTarget._y);
                dragPiece.stopDrag();
                dragTarget._x = 1000;
                dragTarget._y = 1000;
        } else if (dragPiece.hitTest(target_mc1)) {
                trace("else 1");
                dragPiece._x = target_mc1._x;
                dragPiece._y = target_mc1._y;
                drop = 1;
                target_mc1._x = 1000;
                target_mc1._y = 1000;
        } else if (dragPiece.hitTest(target_mc2)) {
                trace("else 2");
                dragPiece._x = target_mc2._x;
                dragPiece._y = target_mc2._y;
                drop = 1;
        } else if (dragPiece.hitTest(target_mc3)) {
                trace("else 3");
                dragPiece._x = target_mc3._x;
                dragPiece._y = target_mc3._y;
                drop = 1;
        } else if (dragPiece.hitTest(target_mc4)) {
                trace("else 4");
                dragPiece._x = target_mc4._x;
                dragPiece._y = target_mc4._y;
                drop = 1;
        } else {
                //trace(originalLocation._x+ "  " +originalLocation._y);
                //trace(dragPiece._x+ "  " +dragPiece._y);
                trace("***********Jump Back***********");
                dragPiece._x = originalLocation._x;
                dragPiece._y = originalLocation._y;
        }
        if (drop == 1) {
                trace("***********Deactivate Drag***********");
                dragPiece.onPress = null;
        }
}
piece_mc1.onRelease = function() {
        checkIfMatching(this, target_mc1, original_mc1);
};
piece_mc2.onRelease = function() {
        checkIfMatching(this, target_mc2, original_mc2);
};
piece_mc3.onRelease = function() {
        checkIfMatching(this, target_mc3, original_mc3);
};
piece_mc4.onRelease = function() {
        checkIfMatching(this, target_mc4, original_mc4);
};
function reset() {
        match = 0;
        activateDrag();
        for (i=1; i<=4; i++) {
                piece = eval("piece_mc"+i);
                target = eval("target_mc"+i);
                targetLoc = eval("targetLoc_mc"+i);
                original = eval("original_mc"+i);
                trace("piece._x "+piece+"  "+piece._x);
                piece._x = original._x;
                piece._y = original._y;
                target._x = targetLoc._x;
                target._y = targetLoc._y;
        }
}

activateDrag();
reset_btn.onPress = Delegate.create(this, reset);




_______________________________________________
Flashcoders@chattyfig.figleaf.com
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to