Thank you very much. I have changed it as below:
package
{
import flash.display.MovieClip;
import flash.events.*;
import flash.geom.Rectangle;
import flash.utils.setInterval;
import flash.utils.clearInterval;
import flash.display.MovieClip;
import flash.display.DisplayObject;
import flash.display.Sprite;
import flash.geom.Point;
import 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;
}
}
}
}