7 Replies Latest reply on Feb 13, 2010 10:44 PM by Harry Kunz

    how to drag and drop and attachmovie?

    flash search Level 1

       

       

       

      Hi all

      Can anyone please tell me how to attach a movie clip to another movie clip after drag and drop .I mean to say that is it possible to make a new movie clip with the target movie clip and dropped movie clip.

      If it is possible please tell me.

       

      Thanks and regards

        • 1. Re: how to drag and drop and attachmovie?
          Ned Murphy Adobe Community Professional & MVP

          My immediate thought is that you could do it using AS3 instead of AS2, because AS3 has the addChild() option.  So when you drop the object you could make it a child of the target.  I cannot think of an equivalent in AS2, though that doesn't mean there is not some aspect or method that would do this.

          • 2. Re: how to drag and drop and attachmovie?
            flash search Level 1

            Thanks for your reply. Actually I m not so much familiar with actionscript3.thats why i need the code in actionscrip2 it will be helpful for the long process.

            Is it possible in actionscript2?

            • 3. Re: how to drag and drop and attachmovie?
              Ned Murphy Adobe Community Professional & MVP

              As far as I know, AS2 does not have a method that provides the ability to join one stage object into another.  The only methods I know of for adding content to other content involves loading it from other resources such as the library (attachMovie()) or external files (loadMovie/loadClip).

              1 person found this helpful
              • 4. Re: how to drag and drop and attachmovie?
                flash search Level 1

                 

                 

                 

                Thanks for your reply. I also think it may not be possible in as2.I tried for this so many options. As I m not so much familiar with as3 I wanted to avoid it. I m sending the flash file with this. Please have a look in this movie the blue box will be collecting from external xml file. My project is to drag the duplicate blue box to the red box and take the two boxes to a next frame.

                      If possible please give some idea or some logic on it and if it is possible in as3 then also please give some idea.

                Thanks and regards

                • 5. Re: how to drag and drop and attachmovie?
                  Ned Murphy Adobe Community Professional & MVP

                  Below is some code for an AS3 example that works.  For this example there are two movieclips with instance names mc1 and mc2.  When you drag mc1 and drop it on mc2, it is added to mc2.  You can also drag mc2 as well to see that it carries mc1 with it after it is added.

                   

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

                  mc2.addEventListener(MouseEvent.MOUSE_DOWN, moveIt);
                  mc2.addEventListener(MouseEvent.MOUSE_UP, dumpIt);

                   

                  function pickUp(event:MouseEvent):void {
                      event.currentTarget.startDrag(true);
                  }

                   

                  function dropIt(event:MouseEvent):void {


                       event.currentTarget.stopDrag();

                   

                       // check if it hit the target
                       if(event.currentTarget.dropTarget != null && event.currentTarget.dropTarget.parent == mc2){

                   

                              // make mc1 undraggable
                              mc1.removeEventListener(MouseEvent.MOUSE_DOWN, pickUp);
                              mc1.removeEventListener(MouseEvent.MOUSE_UP, dropIt);

                             

                              // put mc1 inside mc2 and align it
                              mc2.addChild(mc1);
                              mc1.x = 0;
                              mc1.y = 0;
                       }
                  }

                   

                  function moveIt(event:MouseEvent):void {
                      event.currentTarget.startDrag(true);
                  }

                   

                  function dumpIt(event:MouseEvent):void {
                      event.currentTarget.stopDrag();
                  }

                   

                  In my working version of this, mc1 is a circle and mc2 is a square big enough to fit mc1 inside, both having their registration points centered.

                  1 person found this helpful
                  • 6. Re: how to drag and drop and attachmovie?
                    Harry Kunz Level 4

                    Do you mean if you can attach the blue movieclip to the red one if it is dragged onto it? So meaning the duplicated movieclip (which is a child of the blue movieclip) should become a child of the red movieclip? You cannot attach a movie clip from one location/parent to another in AS2. Only AS3 can do that with the addChild method.

                    • 7. Re: how to drag and drop and attachmovie?
                      Harry Kunz Level 4

                      Do you mean if you can attach the blue movieclip to the red one if it is dragged onto it? So meaning the duplicated movieclip (which is a child of the blue movieclip) should become a child of the red movieclip? You cannot attach a movie clip from one location/parent to another in AS2. Only AS3 can do that with the addChild method. You can do a workaround though to delete the movieclip you dragged onto the red one and do an attachMovie("linkage id in library of blue box") to attach a blue movieclip from the library to the red using it's linkage id.