3 Replies Latest reply on Dec 20, 2010 4:46 AM by Ned Murphy

    Drag and Drop question


      Hi all,


      I'm trying to create a flash animation where the user can click and drag ingredients around a kitchen, following a recipe, in order to make a meal.

      In the situation I am working on now, multiple ingredients need to be dragged into a frying pan, and then a timer appears counting down a specific time to cook those ingredients.


      Does flash enable me to drag a set number of ingredients (movie clips) into a frying pan (movie clip), with any unwanted ingredients being returned to their starting position and have the knowledge to start a timer when it knows those ingredients have been added? (it doesnt matter about the order that they are added)


      Thanks in advance



        • 1. Re: Drag and Drop question
          Ned Murphy Adobe Community Professional & MVP

          Yes, Flash can be coded to manage things in the manner you describe.


          Handling the correct placement of things normally involves checking the _droptarget property of the object that was dropped, but in your case, if it involves dropping objects that shouldn't be dropped, then you'd need somewhat simpler logic that keeps track of who should be dropped versus not for a given recipe..


          You should try to search Google using terms like "AS2 drag and drop tutorial"to find something to get you started.

          • 2. Re: Drag and Drop question
            smiley_bond Level 1

            Thanks for your reply. I've had a look and I come across this code from a game. I've modified it to fit the names I am using for my movieclips but I am getting errors.


            var startX:Number;
            var startY:Number;
            var counter:Number = 0;

            Oil.addEventListener(MouseEvent.MOUSE_DOWN, pickUp);
            Oil.addEventListener(MouseEvent.MOUSE_UP, dropIt);

            function pickUp(event:MouseEvent):void {
            reply_txt.text = "";
            startX = event.target.x;
            startY = event.target.y;

            function dropIt(event:MouseEvent):void {
            var myTargetName:String = "target" + event.target.name;
            var myTarget:DisplayObject = getChildByName(myTargetName);

            if (event.target.dropTarget != null && event.target.dropTarget.parent == myTarget){
              reply_txt.text = "Good Job!";
              event.target.removeEventListener(MouseEvent.MOUSE_DOWN, pickUp);
              event.target.removeEventListener(MouseEvent.MOUSE_UP, dropIt);
              event.target.buttonMode = false;
              event.target.x = myTarget.x;
              event.target.y = myTarget.y;
            } else {
              reply_txt.text = "Try Again!";
              event.target.x = startX;
              event.target.y = startY;
            if(counter == 4){
                    reply_txt.text = "Congrats, you're finished!";

            Oil.buttonMode = true;


            Really, all I need to do is allow the user to drag an object (ingredient) into another object (pan), with the ingredient then dissappearing from view but the holder object knowing what has been dragged into it, and any unwanted ingredients just left behind. I cant get my head round how that could be achieved so if anyone has any ideas that would be great



            • 3. Re: Drag and Drop question
              Ned Murphy Adobe Community Professional & MVP

              That is AS3 code and this is an AS2 forum, so I assume you are looking for an AS2 solution.  Keep searching Google and you should find something.

              1 person found this helpful