6 Replies Latest reply on Aug 22, 2006 10:36 AM by abeall

    Dragging Attached MC's

    VaporAction Level 1
      I want the user to be able to click on an MC which will cause another MC to be attached and then I want the user to be able to drag that MC around without dragging the MC it was attached to...is this possible?
      Here's my code...
        • 1. Re: Dragging Attached MC's
          Level 7

          "VaporAction" <webforumsuser@macromedia.com> wrote in message
          news:ecd3u3$bge$1@forums.macromedia.com...
          >I want the user to be able to click on an MC which will cause another MC to
          >be
          > attached and then I want the user to be able to drag that MC around
          > without
          > dragging the MC it was attached to...is this possible?
          > Here's my code...
          >
          >
          > OriginPositive_mc.onRelease = function() {
          > this.attachMovie ("ParticlePositive", "ParticlePositive_mc",
          > this.getNextHighestDepth())
          > }
          > ParticlePositive_mc.onPress = function() {
          > this.startDrag(false, 0, 0, 650, 368)
          > }
          > ParticlePositive_mc.onRelease = function() {
          > this.stopDrag()
          > }
          >

          Short answer: No.

          You cannot do this without releasing the mouse button and clicking it again
          n the newly attached MC.

          When I do something like this I do not attach the movie to the object I am
          clicking on, I attach to its _parent or _root. Then, instead of using the
          startDrag, stopDrag I use the onmousemove event and move the attached MC
          around with the mouse, until the button is realease... which then gets rid
          of the attached MC.

          for instance:

          var a:MovieClip

          function handlePress():Void {
          a = attachMovie("name", "newName", 1);
          this.onMouseMove = function() {
          a._x = _root._xmouse;
          a._y = _root._ymouse;
          }
          }

          function handleRelease():Void {
          a.removeMovieClip();
          this.onMouseMove = undefined;
          }

          Here, handlePress would be your movie's onPress event handler and
          handleRelease would be the movie's onRelease event handler.

          Just out of curiosity, are you trying to create Drag-and-Drop functionality
          with this?









          • 2. Re: Dragging Attached MC's
            abeall Level 3
            Along the lines of what SMB said, you can jsut re-arrange the code a bit and it should work:

            OriginPositive_mc.onRelease = function() {
            this.attachMovie ("ParticlePositive", "ParticlePositive_mc", this.getNextHighestDepth())

            ParticlePositive_mc.onPress = function() {
            this.startDrag(false, 0, 0, 650, 368)
            }
            ParticlePositive_mc.onRelease = function() {
            this.stopDrag()
            }
            ParticlePositive_mc.onPress();
            }
            • 3. Re: Dragging Attached MC's
              VaporAction Level 1
              I tried your code and it worked fine except the MC didn't show up until I moved the mouse...I'd like for it to show up as soon as you depress the mouse button...I tried using onMouseDown but then you couldn't drag it...also I want the user to have to keep the mouse button depressed to drag it, just like with this.onPress { this.startDrag }...
              • 4. Re: Dragging Attached MC's
                abeall Level 3
                Interesting. Try setting ParticlePositive's _x and _y to the _xmouse and _ymouse in that code block, sometime after attachMovie of course.
                • 5. Re: Dragging Attached MC's
                  VaporAction Level 1
                  I finally got it to work...here's the code I used...
                  • 6. Re: Dragging Attached MC's
                    abeall Level 3
                    That does what you want? Cool, good job.