Drag and Drop Bugs in AIR for iOS
Hi guys,
I'm looking for some reliable drag and drop code that works with multiple objects on the stage.
This code works fine on the web, but in AIR I can tear apart my movieclips, so it's unusable:
Does NOT work:
circle_mc.addEventListener(MouseEvent.MOUSE_DOWN, drag);
square_mc.addEventListener(MouseEvent.MOUSE_DOWN, drag);
stage.addEventListener(MouseEvent.MOUSE_UP, drop);
function drag(e:MouseEvent):void
{
e.target.startDrag(false);
}
function drop(e:MouseEvent):void
{
stopDrag();
}
This Drag code below works in AIR, but is a bit lengthy. Can anyone help me rewrite it for multiple Movieclips? My AS3 isn't that
good yet. Or if you have a better solution, please post it.
Thanks,
Matt
THIS CODE WORKS IN AIR:
// set listeners
Ghost1.addEventListener(MouseEvent.MOUSE_DOWN, startGhostDrag1);
stage.addEventListener(MouseEvent.MOUSE_UP, stopGhostDrag1);
Ghost1.addEventListener(Event.ENTER_FRAME, dragGhost1);
// offset between sprite location and click
var clickOffset:Point = null;
// user clicked
function startGhostDrag1(event:MouseEvent) {
clickOffset = new Point(event.localX, event.localY);
}
// user released
function stopGhostDrag1(event:MouseEvent) {
clickOffset = null;
}
// run every frame
function dragGhost1(event:Event) {
if (clickOffset != null) { // must be dragging
Ghost1.x = mouseX - clickOffset.x;
Ghost1.y = mouseY - clickOffset.y;
}
}
