Groups | Blog | Home
all groups > flash actionscript > april 2005 >

flash actionscript : Drag and drop-- Make not draggable after match



Eric Kuhn
4/12/2005 12:36:22 PM
I want to have a drag and drop that when you drop the item into the correct
area the item is no longer dragable.
Everything so far works except after i match the hit area i can still drag
the item.

This is probably something easy but it is eluding me.

Any suggestions would be appreciated. Code for dragable item is below

onClipEvent (load) {
origX = this._x;
origY = this._y;
}
onClipEvent (mouseDown) {
if (this.hitTest(_root._xmouse, _root._ymouse)) {
this.startDrag();
}
}
onClipEvent (mouseUp) {
if (this.hitTest(_root._xmouse, _root._ymouse)) {
this.stopDrag();

if (_parent.dropZone2.hitTest(this._x, this._y, true)) {
// center it on the drop zone
this._x = _parent.dropZone2._x;
this._y = _parent.dropZone2._y;
_global.drag1 = true;
} else {
this._x = origX;
this._y = origY;
}
}
}


eric

eric
4/13/2005 8:21:10 AM
Thanks for the help- what you both have done has set me in the right
direction.

Thanks!

Eric

Ganesh GV
4/13/2005 8:33:15 AM
Hi

try this

onClipEvent (load) {
origX = this._x;
origY = this._y;
}
onClipEvent (mouseDown) {
//Added few more conditions to check its x & y positions
if (this.hitTest(_root._xmouse, _root._ymouse) && this._x !=
_parent.dropZone2._x & this._y != _parent.dropZone2._y) {
this.startDrag();
}
}
onClipEvent (mouseUp) {
if (this.hitTest(_root._xmouse, _root._ymouse)) {
this.stopDrag();

if (_parent.dropZone2.hitTest(this._x, this._y, true)) {
// center it on the drop zone
this._x = _parent.dropZone2._x;
this._y = _parent.dropZone2._y;
_global.drag1 = true;
} else {
this._x = origX;
this._y = origY;
}
}
}


I have added some more checking before startDrag() ie. if the x & y of both
sourse and dropzone are same then drag won't happen.

hope this works fine for you.



Ajay Vyas
4/13/2005 9:08:48 AM
Here is another method to do this..

onClipEvent (load)
{
isPlaced = false;
origX = this._x;
origY = this._y;
}

onClipEvent (mouseDown)
{
if (this.hitTest(_root._xmouse, _root._ymouse))
{
this.startDrag();
}
}


onClipEvent (mouseUp)
{
if (this.hitTest(_root._xmouse, _root._ymouse))
{
this.stopDrag();

if (_parent.dropZone2.hitTest(this._x, this._y, true) &&
isPlaced == false)
{
// center it on the drop zone
this._x = _parent.dropZone2._x;
this._y = _parent.dropZone2._y;
_global.drag1 = true;
isPlaced = true;
}
else
{
this._x = origX;
this._y = origY;
}
}
}

Hope this is easy for you

Cherrs
Ajay
AddThis Social Bookmark Button