dcsimg
A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: Drag and Drop

  1. #1
    Junior Member
    Join Date
    Jul 2002
    Posts
    21
    I am stumped. I have this square on my stage. There are 10 of these squares and the drag and drop work excellent. However, when the tenth square is dragged I want a rectangle to appear and the squares to go back to their home. Anyone know how I can do this?

    Thanks


    Glenn

  2. #2
    Poof! Whaddya need? I'mFine's Avatar
    Join Date
    May 2001
    Posts
    345

    her you go

    First, Make your rectangle into a movie clip so you can give it an instance name and reference it in AS. Then, you need to "remember" your boxes' starting positions. You'd want to do this in the first frame's action script. If your boxes are named box1, box2, box3, etc. you can do this with a for...in loop as follows:
    Code:
    rectangleClip._visible = false;
    for (i=1; i<=9; ++i) {     
         _root["box"+i].startingX = _root["box"+i]._x;
         _root["box"+i].startingY = _root["box"+i]._y;
    }
    Then, in the tenth box's script, put the following:
    Code:
    onClipEvent (load) {
    	this.onPress = function () {
    		this.startDrag (true);
    		this.dragging = true;
                    rectangleClip._visible = true;
    	}
    	this.onMouseUp = function () {
    		this.stopDrag();
    		this.dragging = false;
    	}
    }
    
    onClipEvent (enterFrame) {
    	if (this.dragging == true) {
               for (i=1; i<=9; ++i) {
          	     _root["box"+i]._x = _root["box"+i].startingX;
        	     _root["box"+i]._y = _root["box"+i].startingY;	   }  
    	}
    }
    Should do it, but reply if you need more help.

    --Rissa

  3. #3
    Junior Member
    Join Date
    Jul 2002
    Posts
    21

    Re: her you go

    Thanks so much for taking the time to do that.

    Glenn

  4. #4
    Poof! Whaddya need? I'mFine's Avatar
    Join Date
    May 2001
    Posts
    345

    my pleasure

    Glenn;

    No prob... just pay it forward.

    --Rissa

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