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

Drag and Drop Bug (Flash, AS3)

New Here ,
Apr 03, 2014 Apr 03, 2014

Hello! Help, please! I'm making a game that involves dragging and dropping books. (Right now there is only one book.) While testing my game, I discovered by accident that no matter where I drag on the screen, the draggable book responds, moving around on screen despite the cursor not being on top of it. Here is my code. (It also snaps a larger book mc to the small one for purposes I intend to use later.)

// Making the small book dragable. //

small_book.addEventListener(MouseEvent.MOUSE_DOWN, fl_ClickToDrag_6);

// when the mouse button is clicked...

function fl_ClickToDrag_6(event:MouseEvent):void

{

    small_book.startDrag();

    big_book_mc.x = small_book.x;///

    big_book_mc.y = small_book.y;///-----> Makes the big book snap to the lil one when clicked.

}

stage.addEventListener(MouseEvent.MOUSE_UP, fl_ReleaseToDrop_6);

// when the mouse button is released...;

function fl_ReleaseToDrop_6(event:MouseEvent):void

{

    small_book.stopDrag();

    big_book_mc.x = small_book.x;///

    big_book_mc.y = small_book.y;///-----> Makes the big book snap to the lil one when the mouse button is released.

}

stage.addEventListener(MouseEvent.MOUSE_DOWN, dragFn);

// if the mouse is currently dragging....;

function dragFn(event:MouseEvent):void

{

    small_book.startDrag();

    big_book_mc.x = small_book.x;///

    big_book_mc.y = small_book.y;///-----> The big book follows while the mouse is dragging.

}

// the small book is now draggable and the big book snaps to it.

TOPICS
ActionScript
513
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
Community Expert ,
Apr 03, 2014 Apr 03, 2014
LATEST

your stage listeners should be added in the mousedown listener functions and then removed in the mouseup listener functions.

and just to clarify, your small book starts dragging no matter where there is a mousedown?

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