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
Thanks for the help- what you both have done has set me in the right direction. Thanks! Eric
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.
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
Don't see what you're looking for? Try a search.
|