9 Replies Latest reply on Mar 24, 2010 4:20 PM by NikolaV97

    Drag and Drop

    MrMadJimmy1

      I'am currently involved in a a project that requires a simple drag and drop.  I know how to create drag and drop.  Unfortunatley that is the extent of it.

       

      I am trying to produce a drag and drop food from a scrolling menu at the side of a plate to drag on to the plate.  I would like the food to copy when dragging over, so if i was to drag and drop the food again that would be possible. 

       

      Im new to actionscript.  Sorry.  Could anyone help?? please.

       

      Thanks

        • 1. Re: Drag and Drop
          kglad Adobe Community Professional & MVP

          duplicate the dropped movieclip (using duplicateMovieClip) and position the duplicate where you want.

          1 person found this helpful
          • 2. Re: Drag and Drop
            MrMadJimmy1 Level 1

            Thanks for the reply.  Im really not experienced

            with actionscript sorry.  You could possible make and example?

            • 3. Re: Drag and Drop
              MrMadJimmy1 Level 1

              i have this at the moment

               

              on (press) {

              startDrag(this,false);

              }

               

              on(release) {

              stopDrag();

              }

               

               

              just dont know how to fit the duplicate in?

              • 4. Re: Drag and Drop
                kglad Adobe Community Professional & MVP

                don't attach code to objects.  attach you code to timelines:

                 

                yourmovieclip.onPress=function(){

                this.startX=this._x;

                this.startY=this._y;

                this.startDrag();

                }

                yourmovieclip.onRelease=yourmovieclip.onReleaseOutside=function(){

                this.stopDrag();

                if(eval(this._droptarget)==droptargetMC){

                var mc:MovieClip=this._parent.duplicateMovieClip(this._name+"_dup",this._parent.getNextHighes tDepth());

                mc._x=this.startX;

                mc._y=this.startY

                mc.onPress=this.onPress;

                mc.onRelease=mc.onReleaseOutside=this.onRelease;

                delete this.onPress;

                } else {

                this._x=this.startX;

                this._y=this.startY;

                }

                 

                }

                • 5. Re: Drag and Drop
                  MrMadJimmy1 Level 1

                  im sorry but that makes no sense to me at all. 

                   

                  ive no experience with actionscript at all.

                   

                  could you explain it? i d be greatful

                   

                  thanks

                  • 6. Re: Drag and Drop
                    kglad Adobe Community Professional & MVP

                     

                    yourmovieclip.onPress=function(){  // onPress handler for your food movieclips.

                    this.startX=this._x;  // stores starting _x

                    this.startY=this._y;

                    this.startDrag();

                    }

                    yourmovieclip.onRelease=yourmovieclip.onReleaseOutside=function(){  //onRelease&onReleaseOutside handler for you food moviieclips

                    this.stopDrag();

                    if(eval(this._droptarget)==droptargetMC){  //checks if food is dropped on plate

                    var mc:MovieClip=this.duplicateMovieClip(this._name+"_dup",this._parent.get NextHighestDepth());  // duplicates this food movieclip

                    mc._x=this.startX;  // assigns starting _x

                    mc._y=this.startY

                    mc.onPress=this.onPress; // assigns onPress for duplicated movieclip

                    mc.onRelease=mc.onReleaseOutside=this.onRelease;

                    delete this.onPress;  // deletes onPress for this so food can't be dragged off plate once dropped onto plate

                    } else {

                    this._x=this.startX;  // if this food is dropped off-plate it's positioned back at its start and not duplicated

                    this._y=this.startY;

                    }

                     

                    }

                    • 7. Re: Drag and Drop
                      MrMadJimmy1 Level 1

                      Thankyou.  Thats great.  Youve been really helpful

                      • 8. Re: Drag and Drop
                        kglad Adobe Community Professional & MVP

                        you're welcome.

                        • 9. Re: Drag and Drop
                          NikolaV97

                          guess that will work, but for unexpirienced, you could just copy/paste the food mc and put each in the same place, make 10 duplicates or more, so when you drag one the other 9 will stay...

                          but still i think that his way is more efficient...