7 Replies Latest reply on Apr 20, 2006 4:08 AM by Finty

    dragable object between cursor and button/mc

      I am creating an activity that involves a drag and drop activity. I have defined dragItems and dragTargets. The dragTargets have rollover events that are triggered when the cursor is over them.

      However, this obviously is never triggered when I am dragging a dragItem on top of them. Is there a workaround to this that generates the same visual confirmation that the cursor is currently over a dragTarget when I am dragging a dragItem?

      thanx in advance
        • 1. Re: dragable object between cursor and button/mc
          blemmo Level 1
          You can use hitTest to achieve this:

          if (dragTarget.hitTest(_xmouse, _ymouse)){
          //mouse is over target, rollOver function here
          }

          greets,
          blemmo
          • 2. Re: dragable object between cursor and button/mc
            Level 1
            thanks for the quick reply. would I do this within;

            onClipEvent(enterFrame){
            if (this.hitTest(_xmouse, _ymouse)){
            //mouse is over target, rollOver function here
            this.onRollOver = function(){
            trace("over!");
            }
            this.onRollOut = function(){
            trace("out");
            }
            }
            }

            Is this the most efficient way?
            • 3. Re: dragable object between cursor and button/mc
              Level 1
              no Blemmo. This doesn't actually work.

              When I am dragging something over the dragTarget then the cursor is not in contact with the target because the dragable item is inbetween them!

              Therefore the hitTest code doesn't get a chance to be triggered.
              • 4. Re: dragable object between cursor and button/mc
                blemmo Level 1
                I think hitTest just checks if the specified position (the mouse position) is inside the target's space, so it shouldn't matter how many objects are between mouse and target.
                In the code you posted, you did assign the rollOver event when the hitTest returns true. As the rollOver event won't fire, this has no results. Just place the code that should be executed there:
                onClipEvent(enterFrame){
                if (this.hitTest(_xmouse, _ymouse)){
                //mouse is over target, rollOver function here
                trace("over!");
                }

                Do you also want something to happen when the mouse leaves the target area (like rollOut)? This is a bit more difficult, but doable. I can give an example, if you need it. But first, try if the above code works (it should, but I haven't tested).
                • 5. Re: dragable object between cursor and button/mc
                  blemmo Level 1
                  Oops... you have to use _root._xmouse in the clipEvent. Try this code:
                  --
                  onClipEvent (enterFrame) {
                  if (this.hitTest(_root._xmouse, _root._ymouse)) {
                  if (!this.mouseover){
                  //mouse is over target, rollOver function here
                  trace("rollover");
                  this.mouseover = true;
                  }
                  }
                  else if (this.mouseover){
                  this.mouseover = false;
                  trace("rollout");
                  }
                  }
                  --
                  It behaves like a button, the rollOver is triggered once when the mouse enters the MC, and the rollOut is triggered when it leaves.

                  cheers,
                  blemmo
                  • 6. Re: dragable object between cursor and button/mc
                    blemmo Level 1
                    Well, I just tried to use the rollOver event, and it works fine, no matter if there's a dragged MC under the cursor or not. So there may be something wron with the code you use. If you'd rather use the rollOver event, post the code you used when it was not working.

                    • 7. Re: dragable object between cursor and button/mc
                      Level 1
                      thanks. This is very useful to me