Copy link to clipboard
Copied
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.
Copy link to clipboard
Copied
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?
Find more inspiration, events, and resources on the new Adobe Community
Explore Now