非常感谢你。我已将其更改如下: package { import flash.display.MovieClip; 导入 flash.events.*;导入 flash.geom.Rectangle;导入 flash.utils.setInterval;导入 flash.utils.clearInterval;导入 flash.display.MovieClip;导入 flash.display.DisplayObject;导入 flash.display.Sprite;导入 flash.geom.Point;导入 flash.utils.Dictionary;
public class DragSync {
private var _dragStartCoordinates:Point = null;
private var _siblingsDragStartCoordinates:Dictionary = null;
private var _primaryItem:Object = null;
私有 var _workSpace:Object = null; 私有变量 _dragWithPrimary:Array = null;
public function DragSync(primaryItem:Object,workSpace:Object, dragWithPrimary:Array)
{
_primaryItem = primaryItem;
_dragWithPrimary = dragWithPrimary;
_workSpace = workSpace;
_workSpace.addEventListener(MouseEvent.MOUSE_DOWN, mouseDownHandler);
_workSpace.addEventListener(MouseEvent.MOUSE_UP, dragMouseUpHandler);
_workSpace.addEventListener(MouseEvent.MOUSE_MOVE, dragMouseMoveHandler);
_workSpace.addEventListener(MouseEvent.MOUSE_OUT, dragOut);
}
private function mouseDownHandler(event:MouseEvent):void
{
trace("event mouse down");
_primaryItem.startDrag();
_dragStartCoordinates = new Point(_primaryItem.x, _primaryItem.y);
_siblingsDragStartCoordinates = new Dictionary(true);
for each (var sibling:DisplayObject in _dragWithPrimary)
{
_siblingsDragStartCoordinates[sibling] = new Point(sibling.x, sibling.y)
}
}
private function dragMouseUpHandler(event:MouseEvent):void
{
moveSiblings();
_primaryItem.stopDrag();
_dragStartCoordinates = null;
_siblingsDragStartCoordinates = null;
}
private function dragMouseMoveHandler(event:MouseEvent):void
{
trace("event mouse MOVE MOVE");
moveSiblings();
}
私有函数dragOut(事件:MouseEvent):无效{_primaryItem.stopDrag();}
// expects _dragStartCoordinates and _siblingsDragStartCoordinates
// to be set
private function moveSiblings():void
{
if (!_dragStartCoordinates || !_siblingsDragStartCoordinates) return;
var xDiff:Number = _primaryItem.x - _dragStartCoordinates.x;
var yDiff:Number = _primaryItem.y - _dragStartCoordinates.y;
for each (var sibling:DisplayObject in _dragWithPrimary)
{
sibling.x = _siblingsDragStartCoordinates[sibling].x + xDiff;
sibling.y = _siblingsDragStartCoordinates[sibling].y + yDiff;
}
}
}
}