Skip to main content
quixotic
Participant
June 16, 2014
Answered

make a movieclip visible when an object is dragged onto it

  • June 16, 2014
  • 1 reply
  • 190 views

i am ridiculously new to codeing in flash (or any program) and am trying to make a movieclip only visible when a object is dragged onto it, can someone show me the code for that?

This topic has been closed for replies.
Correct answer Ned Murphy

Something like the following might work (not tested)...

movieclip.alpha = 0;
object.addEventListener(MouseEvent.MOUSE_DOWN, dragObject);

function dragObject(evt:MouseEvent):void {
      object.startDrag();
      stage.addEventListener(MouseEvent.MOUSE_MOVE, checkObject);
      stage.addEventListener(MouseEvent.MOUSE_UP, endDrag);
}

function checkObject(evt:MouseEvent):void {
      if(object.hitTestObject(movieclip)){
          movieclip.alpha = 1;
      } else {
          movieclip.alpha = 0;
      }
}

function endDrag(evt:MouseEvent):void {
      stage.removeEventListener(MouseEvent.MOUSE_MOVE, checkObject);
      stage.removeEventListener(MouseEvent.MOUSE_UP, endDrag);
}

1 reply

Ned Murphy
Ned MurphyCorrect answer
Legend
June 16, 2014

Something like the following might work (not tested)...

movieclip.alpha = 0;
object.addEventListener(MouseEvent.MOUSE_DOWN, dragObject);

function dragObject(evt:MouseEvent):void {
      object.startDrag();
      stage.addEventListener(MouseEvent.MOUSE_MOVE, checkObject);
      stage.addEventListener(MouseEvent.MOUSE_UP, endDrag);
}

function checkObject(evt:MouseEvent):void {
      if(object.hitTestObject(movieclip)){
          movieclip.alpha = 1;
      } else {
          movieclip.alpha = 0;
      }
}

function endDrag(evt:MouseEvent):void {
      stage.removeEventListener(MouseEvent.MOUSE_MOVE, checkObject);
      stage.removeEventListener(MouseEvent.MOUSE_UP, endDrag);
}

quixotic
quixoticAuthor
Participant
June 16, 2014

it worked perfectly, thank you so much!

Ned Murphy
Legend
June 17, 2014

You're welcome