I'm an amatuer in As3. I need to complete my first project in drag drop game using an As3. The problem is I did not get a match coding to align the draggable movie clips to another movie clip. I want to make a complete train with dragging the body of the train to its head by following the order of the complete train example given. I have three movie clips of train body and a movie clip of train head. What I want to do is dragging the train body to its head by following the arrangement of the example complete train given with using drag drop play style. If the correct body train is drag to its head, then it will align and another train body is appear and will repeat the same way until its complete.
Anyone know how to do this? please, any help would be really nice.
Thanks
So here is my code :
stop();
import flash.display.MovieClip;
var orig1X:Number=body_mc.x;
var orig1Y:Number=body_mc.y;
var orig2X:Number=body1_mc.x;
var orig2Y:Number=body1_mc.y;
var orig3X:Number=body2_mc.x;
var orig3Y:Number=body2_mc.y;
body_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragTheObject);
body_mc.addEventListener(MouseEvent.MOUSE_UP, bodyRelease);
body1_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragTheObject);
body1_mc.addEventListener(MouseEvent.MOUSE_UP, body1Release);
body2_mc.addEventListener(MouseEvent.MOUSE_DOWN, dragTheObject);
body2_mc.addEventListener(MouseEvent.MOUSE_UP, body2Release);
function dragTheObject(event:MouseEvent):void {
var item:MovieClip=MovieClip(event.target);
addChild(item);
item.startDrag();
var topPos:uint=this.numChildren-1;
this.setChildIndex(item, topPos);
}
function bodyRelease(event:MouseEvent):void {
var item:MovieClip=MovieClip(event.target);
item.stopDrag();
if (head_mc.hitTestPoint(item.x,item.y)) {
item.x=head_mc.x;
item.y=head_mc.y;
}
else {
item.x=orig1X;
item.y=orig1Y;
}
};
function body1Release(event:MouseEvent):void {
var item:MovieClip=MovieClip(event.target);
item.stopDrag();
if (head_mc.hitTestPoint(item.x,item.y)) {
item.x=head_mc.x;
item.y=head_mc.y;
}
else {
item.x=orig2X;
item.y=orig2Y;
}
};
function body2Release(event:MouseEvent):void {
var item:MovieClip=MovieClip(event.target);
item.stopDrag();
if (head_mc.hitTestPoint(item.x,item.y)) {
item.x=head_mc.x;
item.y=head_mc.y;
}
else {
item.x=orig3X;
item.y=orig3Y;
}
};