A Flash Developer Resource Site

Results 1 to 5 of 5

Thread: Disabling a drag-and-drop asset?

  1. #1
    Junior Member
    Join Date
    Dec 2005
    Posts
    2

    Disabling a drag-and-drop asset?

    Hello everyone.


    I'm painfully new to actionscripting and need some advice on how to go about disabling a drag-and-drop object. Basically I have this puzzle I'm working on, and it has pieces that you can drag and drop into place. That was simple enough to implement. Now the problem is, once the piece is in place, I want to be able to disable the drag-and-drop functionality, so it cannot be mainuplated further.

    How can I go about doing this? I've read through dozens of tutorials and looked through my flash Actionscript manual and help file, but nothing that I've seen gives any details or hints as to how to go about accomplishing this. If anyone could give me some advice, or point me in the right direction to resources that spell it out, I would be very appreciative.



    Thanks in advance.

  2. #2

  3. #3
    Junior Member
    Join Date
    Dec 2005
    Posts
    2
    That portion is in there, but yet I can still grab it again after I release the mouse button.

    The code I'm using looks something like this:

    Code:
    // On press, move depth above other elements so it's on top
    on(press) {
    		this.swapDepths(100);
    		startDrag(this);
    }
    
    // On release, if it's above it's proper slot, snap into place, otherwise go back
    	on(release) {
    		stopDrag();
    		if (this._droptarget == "/TosCYi") {
    			this._x=32.0;
    			this._y=128.6;
    			
    		}
    		else{
    			this._x=32;
    			this._y=189.4;
    			
    		}
    }

  4. #4
    An FKer
    Join Date
    Sep 2005
    Location
    Ontario
    Posts
    1,167
    Hey,

    You can always use a boolean variable (true/false) to determine if the user can drag the movieclip.

    On your movieclip add a:

    code:
      onClipEvent (load) {
    something = false;
    }
    on (press) {
    if (this.something == false){
    this.startDrag();
    }
    }
    on (release) {
    this.stopDrag();
    this.something = true;
    }



    So in other words when you press on the movieclip object it first checks if the variable 'something' (sorry, couldnt think of a better word) is false. If it is then it allows the movieclip to be dragged

    When you release the movieclip, it sets the variable 'something' to true so the next time you try to drag the movieclip, since the variable is set to true the if statment fails therefore not allowing the user to drag it

    Good luck

  5. #5
    Senior Member
    Join Date
    Jan 2006
    Posts
    106

    drag and drop disable

    I could not get the code above to work, could someone look at my code and help me? I would like an object to be disabled after it has been release. Until the user hit reset button later. I even tried to put a simple StopDrag (); after "onClipEvent (mouseUp) " with no luck.

    here is the code:
    onClipEvent (load) {
    origX = this._x;
    origY = this._y;
    }
    onClipEvent (mouseDown)

    {
    if (this.hitTest(_root._xmouse, _root._ymouse)) {
    this.swapDepths(100); // depth
    this.swapDepths (drag1); // target
    this.startDrag();
    this.gotoAndStop(1);
    }
    }

    onClipEvent (mouseUp) {
    StopDrag ();
    if (this.hitTest(_root._xmouse, _root._ymouse)) {
    this.swapDepths(-1);
    this.swapDepths (_parent);
    this.stopDrag();
    // see if the dragbutton is on top of another dragbutton
    if (this.hitTest(_root.drag1._x,_root.drag1._y,true)) {
    this._x = origX;
    this._y = origY;
    }
    else if(_root.drag2.hitTest(this._x,this._y,true)) {
    this._x = origX;
    this._y = origY;

    }
    else if (_root.drag3.hitTest(this._x,this._y,true)) {
    this._x = origX;
    this._y = origY;
    }
    else if (_root.drag5.hitTest(this._x,this._y,true)) {
    this._x = origX;
    this._y = origY;
    }
    // see if the dropZone conatins the center of this mc
    if (_parent.dropZone1.hitTest(this._x,this._y,true)) {

    // center it on the drop zone
    this._x = this.dropZone1._x = 163;
    this._y = this.dropZone1._y = 146;
    this.gotoAndStop(3);
    } else {
    if (_parent.dropZone2.hitTest(this._x,this._y,true)) {

    // center it on the drop zone
    this._x = this.dropZone2._x = 430;
    this._y = this.dropZone2._y = 150;
    this.gotoAndStop(3);
    } else {
    if (_parent.dropZone3.hitTest(this._x,this._y,true)) {

    // center it on the drop zone
    this._x = this.dropZone3._x = 163;
    this._y = this.dropZone3._y = 326;
    this.gotoAndStop(3);
    } else {
    if (_parent.dropZone4.hitTest(this._x,this._y,true)) {

    // center it on the drop zone
    this._x = this.dropZone4._x = 163;
    this._y = this.dropZone4._y = 416;
    this.gotoAndStop(2);
    } else {
    if (_parent.dropZone5.hitTest(this._x,this._y,true)) {

    // center it on the drop zone
    this._x = this.dropZone5._x = 163;
    this._y = this.dropZone5._y = 506;
    this.gotoAndStop(3);
    } else {
    // return it to its original location
    this._x = origX;
    this._y = origY;
    }
    }
    }}}}}

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center