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

make a movieclip visible when an object is dragged onto it

New Here ,
Jun 16, 2014 Jun 16, 2014

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?

TOPICS
ActionScript
170
Translate
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 , Jun 16, 2014 Jun 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;
      }
}

functio

...
Translate
LEGEND ,
Jun 16, 2014 Jun 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);
}

Translate
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
New Here ,
Jun 16, 2014 Jun 16, 2014

it worked perfectly, thank you so much!

Translate
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 ,
Jun 17, 2014 Jun 17, 2014
LATEST

You're welcome

Translate
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