どうもありがとうございました。以下のように変更しました: 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;
private var _workSpace:Object = null; private var _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();
}
private function dragOut(event:MouseEvent):void { _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;
}
}
}
}