A Flash Developer Resource Site

Results 1 to 4 of 4

Thread: startdrag movie

  1. #1

    startdrag movie

    hi guys,

    i need to make a mc draggable.. also to provide buttons, when clicked, will move the mc to a specific spot.

    at present, i put the draggable mc, mc_drag, into a mc container, mc_contain.

    i am able to drag the mc_drag around, when i click the buttons, it goes to the specific spot, all's well. BUT when i try to drag the mc_drag again.. it keeps hopping back to the specific spot ..

    Code:
    gotoblahh_btn.onPress = function() {
    	_root.mc_contain.mc_drag.onEnterFrame = moveto(145,75);	
    };
    
    function moveto(xcoord, ycoord){	
    	this.onEnterFrame = function() {
    		_root.mc_contain.mc_drag._x = 0;
    		_root.mc_contain.mc_drag._y = 0;
    		if (_root.cutthecrap == "more") {
    			_root.yChange = Math.round(ycoord-_root.mc_contain._y);
    			_root.xChange = Math.round(xcoord-_root.mc_contain._x);
    			_root.yMove = Math.round(_root.yChange/10);
    			_root.xMove = Math.round(_root.xChange/10);
    			_root.mc_contain._y += _root.yMove;
    			_root.mc_contain._x += _root.xMove;	
    		}
          //for some reason, _root.mc_contain._x will never be equal to xcoord, is there some problem with my moveto code?
    		if ((_root.mc_contain._x == xcoord) && (_root.mc_contain._y == ycoord)){
    			delete _root.mc_contain.mc_drag.onEnterFrame;
    		}
    	}
    }

    i appreciate the help! thanks

  2. #2
    Code:
    // all of this is on the root timeline
    //  this code
    //  a button named gotoblahh_btn
    //  a mc named mc_contain
    //      inside mc_contain is a mc named mc_drag
    gotoblahh_btn.onPress = function() {
    	moveto(145, 75);
    	momentum = 10;
    };
    
    function moveto(xcoord, ycoord) {
    	xDestination = xcoord;
    	yDestination = ycoord;
    	this.onEnterFrame = function() {
    			var yChange = ycoord-mc_contain.mc_drag._y;
    			var xChange = xcoord-mc_contain.mc_drag._x;
    			mc_contain.mc_drag._y += yChange/momentum;
    			mc_contain.mc_drag._x += xChange/momentum;
    			momentum *= .85;// decrease the momentum
    		if ((mc_contain.mc_drag._x == xDestination) && (mc_contain.mc_drag._y == yDestination)) {
    			delete this.onEnterFrame;
    			trace("finished moving")
    		}
    	};
    }
    mc_contain.mc_drag.onPress = function() {
    	startDrag(this);
    };
    mc_contain.mc_drag.onRelease = function() {
    	stopDrag();
    };

  3. #3
    oops.. just take out all that bit about xDestination and yDestination.. it works fine without it. And make sure you change the if statement to
    if ((mc_contain.mc_drag._x == xcoord) && (mc_contain.mc_drag._y == ycoord)) {

  4. #4
    great!
    thanks mike!!

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