• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

Help with code

Community Beginner ,
Feb 14, 2010 Feb 14, 2010

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);
}

TOPICS
ActionScript

Views

309

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Feb 14, 2010 Feb 14, 2010

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.

Votes

Translate

Translate
LEGEND ,
Feb 14, 2010 Feb 14, 2010

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.

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Feb 14, 2010 Feb 14, 2010

Copy link to clipboard

Copied

Thanks!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
LEGEND ,
Feb 14, 2010 Feb 14, 2010

Copy link to clipboard

Copied

LATEST

You're welcome

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines