3 Replies Latest reply on Jul 12, 2006 7:39 AM by Newsgroup_User

    make dynamic mc draggable

    Level 7
      Hi All,

      I have some code to drag and drop a movieclip. The code works ok if it
      is inside the movieclip and in my old flash photo gallery the clips were
      put in manually and the photos added by xml.

      onClipEvent (mouseDown) {
      if (this.hitTest(_root._xmouse, _root._ymouse)) {
      this.setDepthTo(kTop)
      this.startDrag();
      }
      }

      onClipEvent (mouseUp) {
      if (this.hitTest(_root._xmouse, _root._ymouse)) {
      this.stopDrag();

      }
      }

      In my new slideshow I am adding the photos using xml and dynamically
      creating the movieclip and loading the photos. Therefore, there is no
      physical movieclip to add code to manually. How can I add this code to
      the movieclip as it is created and loaded so that it becomes draggable?
      Or, how do I make a dynamically loaded movieclip loaded with a jpeg
      draggable?

      Thanks for any advice,

      Jeff C

        • 1. Re: make dynamic mc draggable
          blemmo Level 1
          Those clip events have a similar expression in dot syntax. For the mouse events it's
          mc_instance.onMouseDown
          and
          mc_instance.onMouseUp

          So you could use your old code with those:
          --
          mc_instance.onMouseDown = function(){
          if (this.hitTest(_root._xmouse, _root._ymouse)) {
          this.setDepthTo(kTop)
          this.startDrag();
          }
          }
          --

          Just make sure the jpg is already loaded, because a call to loadMovie can remove the events assigned to the MC. So it's safer to use some preloading code or the MovieClipLoader, and assign the mouse events when the loading is finished.

          hth,
          blemmo
          • 2. Re: make dynamic mc draggable
            Level 7
            Thanks Blemmo,

            I'll give it a try when I get home from work. Thanks for the help.

            Jeff C

            blemmo wrote:

            >Those clip events have a similar expression in dot syntax. For the mouse events
            >it's
            > mc_instance.onMouseDown
            > and
            > mc_instance.onMouseUp
            >
            > So you could use your old code with those:
            > --
            > mc_instance.onMouseDown = function(){
            > if (this.hitTest(_root._xmouse, _root._ymouse)) {
            > this.setDepthTo(kTop)
            > this.startDrag();
            > }
            > }
            > --
            >
            > Just make sure the jpg is already loaded, because a call to loadMovie can
            >remove the events assigned to the MC. So it's safer to use some preloading code
            >or the MovieClipLoader, and assign the mouse events when the loading is
            >finished.
            >
            > hth,
            > blemmo
            >
            >
            >
            • 3. Re: make dynamic mc draggable
              Level 7
              Thanks Blemmo,

              I put the code in the 'onLoadInit' function and it works a treat. Thanks
              for the tip.

              targetMC.onMouseDown = function(){
              if (this.hitTest(_root._xmouse, _root._ymouse)) {
              var nextDepth:Number = this.getNextHighestDepth();
              this.setDepthTo(nextDepth)
              this.startDrag();
              }
              }

              targetMC.onMouseUp = function(){
              if (this.hitTest(_root._xmouse, _root._ymouse)) {
              this.stopDrag();
              }
              }


              Thanks,

              Jeff C.

              blemmo wrote:

              >Those clip events have a similar expression in dot syntax. For the mouse events
              >it's
              > mc_instance.onMouseDown
              > and
              > mc_instance.onMouseUp
              >
              > So you could use your old code with those:
              > --
              > mc_instance.onMouseDown = function(){
              > if (this.hitTest(_root._xmouse, _root._ymouse)) {
              > this.setDepthTo(kTop)
              > this.startDrag();
              > }
              > }
              > --
              >
              > Just make sure the jpg is already loaded, because a call to loadMovie can
              >remove the events assigned to the MC. So it's safer to use some preloading code
              >or the MovieClipLoader, and assign the mouse events when the loading is
              >finished.
              >
              > hth,
              > blemmo
              >
              >
              >