5 Replies Latest reply on Feb 16, 2017 3:43 AM by jackh8500410

    Drag and drop matching game... again (sorry)!

    jackh8500410 Level 1

      Hi all,

       

      I was hoping not to post about this again, but trouble has hit again.

       

      On the matching game, when the user matches 2 objects and then presses the back button to go to the main menu, the draggable object stays on the screen.

      I thought of removing the event listener but this is already done in the code!

       

      Does anyone know how to stop the object from staying on screen?

      This shows the object being matched:

      Capture1.PNG

       

      This shows the object staying on the main menu:

       

      Capture2.PNG

       

      Thanks,

      Jack

        • 1. Re: Drag and drop matching game... again (sorry)!
          ClayUUID Adobe Community Professional

          Post your drag start code.

           

          Also fix that "requiured".

          • 2. Re: Drag and drop matching game... again (sorry)!
            jackh8500410 Level 1

            Firstly, well noticed on the bad spelling

             

            So to pickup an object;

            function pickupObject(event: MouseEvent): void {

              event.currentTarget.startDrag();

              event.currentTarget.parent.addChild(event.currentTarget);

              objectoriginalX = event.currentTarget.x;

              objectoriginalY = event.currentTarget.y;

            }

             

            To drop an object;

             

            function dropObject(event: MouseEvent): void {

              event.currentTarget.stopDrag();

              var matchingTargetName: String = "target" + event.currentTarget.name;

              var matchingTarget: DisplayObject = getChildByName(matchingTargetName);

              if (event.currentTarget.dropTarget != null && event.currentTarget.dropTarget.parent == matchingTarget) {

              event.currentTarget.removeEventListener(MouseEvent.MOUSE_DOWN, pickupObject);

              event.currentTarget.removeEventListener(MouseEvent.MOUSE_UP, dropObject);

              event.currentTarget.buttonMode = false;

              event.currentTarget.x = matchingTarget.x;

              event.currentTarget.y = matchingTarget.y;

              } else {

              event.currentTarget.x = objectoriginalX;

              event.currentTarget.y = objectoriginalY;

              }

            }

             

            Thanks

            • 3. Re: Drag and drop matching game... again (sorry)!
              ClayUUID Adobe Community Professional

              Are you sure you shouldn't be using target instead of currentTarget? I'm no AS3 expert, but that event.currentTarget.parent.addChild(event.currentTarget); line may be ripping the drags out of their container, which would explain why they're not going away.

              • 4. Re: Drag and drop matching game... again (sorry)!
                jackh8500410 Level 1

                Just tried this and it's still having the same problem;

                 

                event.target.parent.addChild(event.currentTarget);

                event.target.parent.addChild(event.target);

                event.currentTarget.parent.addChild(event.target);

                 

                And I tried taking all currentTarget's out, replacing with target and that's not done anything.

                 

                PS: I don't know what I should be using, it was suggested by another forum member. I don't know the difference, though I have since googled it but I still don't know

                • 5. Re: Drag and drop matching game... again (sorry)!
                  jackh8500410 Level 1

                  I've made a quick fix.

                   

                  When the frame loads, all of the objects are made visible and when the back button is pressed I've made them invisible.

                   

                  Perfecto!