Skip to main content
April 20, 2006
Answered

dragable object between cursor and button/mc

  • April 20, 2006
  • 7 replies
  • 535 views
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
This topic has been closed for replies.
Correct answer blemmo
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

7 replies

April 20, 2006
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.
Inspiring
April 20, 2006
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).
blemmoCorrect answer
Inspiring
April 20, 2006
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
Inspiring
April 20, 2006
You can use hitTest to achieve this:

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

greets,
blemmo
April 20, 2006
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?