Skip to content

Instantly share code, notes, and snippets.

@deepaksharma192
Created June 29, 2013 09:58
Show Gist options
  • Save deepaksharma192/5890595 to your computer and use it in GitHub Desktop.
Save deepaksharma192/5890595 to your computer and use it in GitHub Desktop.
Drag and Drop In as3 flash
stop();
var startX:Number;
var startY:Number;
drag_1.addEventListener(MouseEvent.MOUSE_DOWN,m_d);
drag_2.addEventListener(MouseEvent.MOUSE_DOWN,m_d);
drag_3.addEventListener(MouseEvent.MOUSE_DOWN,m_d);
drag_4.addEventListener(MouseEvent.MOUSE_DOWN,m_d);
drag_1.addEventListener(MouseEvent.MOUSE_UP,m_u_1);
drag_2.addEventListener(MouseEvent.MOUSE_UP,m_u_2);
drag_3.addEventListener(MouseEvent.MOUSE_UP,m_u_3);
drag_4.addEventListener(MouseEvent.MOUSE_UP,m_u_4);
function m_d(e:Event) {
e.target.startDrag();
startX = e.target.x;
startY = e.target.y;
}
function m_u_1(e:Event) {
drag_1.removeEventListener(MouseEvent.MOUSE_DOWN,m_d);
e.target.stopDrag();
if (drag_1.dropTarget != null && drag_1.dropTarget.parent==drop_4 || drag_1.dropTarget != null && drag_1.dropTarget.parent==drop_3|| drag_1.dropTarget != null && drag_1.dropTarget.parent==drop_2 || drag_1.dropTarget != null && drag_1.dropTarget.parent==drop_1) {
trace("RRRRRRRRRRRRRRRRRRRR");
drag_1.x=e.target.x;
drag_1.y=e.target.y;
} else {
trace("wwwwwwwwwwwwwwww");
e.target.x = startX;
e.target.y = startY;
}
}
function m_u_2(e:Event) {
drag_2.removeEventListener(MouseEvent.MOUSE_DOWN,m_d);
e.target.stopDrag();
if (drag_2.dropTarget != null && drag_2.dropTarget.parent==drop_4 || drag_2.dropTarget != null && drag_2.dropTarget.parent==drop_3|| drag_2.dropTarget != null && drag_2.dropTarget.parent==drop_2 || drag_2.dropTarget != null && drag_2.dropTarget.parent==drop_1) {
trace("RRRRRRRRRRRRRRRRRRRR");
drag_2.x=e.target.x;
drag_2.y=e.target.y;
} else {
trace("wwwwwwwwwwwwwwww");
e.target.x = startX;
e.target.y = startY;
}
}
function m_u_3(e:Event) {
drag_3.removeEventListener(MouseEvent.MOUSE_DOWN,m_d);
e.target.stopDrag();
if (drag_3.dropTarget != null && drag_3.dropTarget.parent==drop_4 || drag_3.dropTarget != null && drag_3.dropTarget.parent==drop_3|| drag_3.dropTarget != null && drag_3.dropTarget.parent==drop_2 || drag_3.dropTarget != null && drag_3.dropTarget.parent==drop_1) {
trace("RRRRRRRRRRRRRRRRRRRR");
drag_3.x=e.target.x;
drag_3.y=e.target.y;
} else {
trace("wwwwwwwwwwwwwwww");
e.target.x = startX;
e.target.y = startY;
}
}
function m_u_4(e:Event) {
drag_4.removeEventListener(MouseEvent.MOUSE_DOWN,m_d);
e.target.stopDrag();
if (drag_4.dropTarget != null && drag_4.dropTarget.parent==drop_4 || drag_4.dropTarget != null && drag_4.dropTarget.parent==drop_3|| drag_4.dropTarget != null && drag_4.dropTarget.parent==drop_2 || drag_4.dropTarget != null && drag_4.dropTarget.parent==drop_1) {
trace("RRRRRRRRRRRRRRRRRRRR");
drag_4.x=e.target.x;
drag_4.y=e.target.y;
} else {
trace("wwwwwwwwwwwwwwww");
e.target.x = startX;
e.target.y = startY;
}
}
submit.addEventListener(MouseEvent.MOUSE_UP,m_submit);
function m_submit(e:Event){
if (drag_1.dropTarget != null && drag_1.dropTarget.parent==drop_2){
trace("----RR-----drag_1-------RR-------");
}else{
trace("----WW-----drop_1-------WW-------");
}
if (drag_2.dropTarget != null && drag_2.dropTarget.parent==drop_4){
trace("----RR-----drag_2-------RR-------");
}else{
trace("----WW-----drop_2-------WW-------");
}
if (drag_3.dropTarget != null && drag_3.dropTarget.parent==drop_1){
trace("----RR-----drag_3-------RR-------");
}else{
trace("----WW-----drop_3-------WW-------");
}
if (drag_4.dropTarget != null && drag_4.dropTarget.parent==drop_3){
trace("----RR-----drag_4-------RR-------");
}else{
trace("----WW-----drop_4-------WW-------");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment