Copy link to clipboard
Copied
I'm making a flash file where there are a few objects, and the alpha value of the object changes when I cursor over the object, and I drag it. It's working fine except when I drag one object over an object that is on top of it. When I do that and I let go of the mose button, the oject on top becomes semitransparent, while the bottom object is still semitransparent. I would like it to be done without having to name specific objects.
Here's the code:
(I also attached a fla file if you want to see it.)
addEventListener(MouseEvent.MOUSE_OVER, hover);
addEventListener(MouseEvent.MOUSE_OUT, offObj);
function hover(e:MouseEvent):void
{
if (DandDactive == 0)
{
e.target.alpha = .7
trace("Now over " + e.target.name);
}
}
function offObj(e:MouseEvent):void
{
if (DandDactive == 0)
{
e.target.alpha = 1;
trace("Now off " + e.target.name);
}
}
var DandDactive:Number = 0;
//drag and drop
addEventListener(MouseEvent.MOUSE_DOWN, dragObj);
addEventListener(MouseEvent.MOUSE_UP, dropObj);
function dragObj (e:MouseEvent):void
{
e.target.startDrag();
DandDactive = 1;
e.target.alpha = .4;
trace("Now dragging " + e.target.name);
}
function dropObj (e:MouseEvent):void
{
e.target.stopDrag();
DandDactive = 0;
e.target.alpha = .7;
trace("Stopped dragging " + e.target.name);
}
The easiest solution might be to just place the dragged object on the top, unless you need to retain them stacked as they are. You can do this using addChild(MovieClip(e.target)) in your dragObj function.
Copy link to clipboard
Copied
The easiest solution might be to just place the dragged object on the top, unless you need to retain them stacked as they are. You can do this using addChild(MovieClip(e.target)) in your dragObj function.
Copy link to clipboard
Copied
Thanks!
Copy link to clipboard
Copied
You're welcome