Results 1 to 5 of 5

Thread: Random xy ease + drag issues

  1. #1
    Join Date
    May 2007
    Posts
    71
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Random xy ease + drag issues

    I am trying to have a movieclip ease into a random position. Then the mc is dragable and swaps depth with the other mc's in the movie.

    Here is the code I have so far but my random positioning is interfering with the dragability of the mc. Once the mc eases into its random position if you try and drag it anywhere it wants to lock back to the x y coordinate that it randomly eased to...

    Code:
    acceleration = 10
    newpos = function () {
    	ranx = Math.round((Math.random ()*250));
    	rany = Math.round ((Math.random ()*250));
    }
    newpos();
    this.onEnterFrame = function() {
    	this._x += ((ranx-this._x)/acceleration);
    	this._y += ((rany-this._y)/acceleration);
    };
    
    drag9.onPress = function() {
    	_root.slide9.startDrag();
    	_root.slide9.swapDepths(_root.getNextHighestDepth());
    }
    drag9.onRelease = drag.onReleaseOutside = function() {
    	_root.slide9.stopDrag();
    }

  2. #2
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    That's because you're setting the x and y coordinates in an onEnterFrameEvent. That means that event fires once a frame. So, you're continuously setting the x and y coordinates equal to the random coordinates.

    I'd suggest that you use a tween to ease the MC. That'll allow you to get rid of the onEnterFrame and get rid of this problem. That would also be a more efficient use of system resources.

    At the very least delete the onEnterFrame after the MC is at the desired coordiates. You could do it within the onPress function. But, I suggest doing it within the onEnterFrame itself (with the use of a conditional).

  3. #3
    Join Date
    May 2007
    Posts
    71
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    I am trying to figure out what the best conditional statement would be for it to only set the x and y coordinates randomly once, and once the coordinates have been set for the initial landing then to release them to allow for the drag function to work properly.

  4. #4
    Join Date
    Jun 2007
    Posts
    543
    Thanks
    3
    Thanked 78 Times in 78 Posts
    Blog Entries
    1

    Default

    try:
    Code:
    acceleration = 10
    newpos = function () {
    	ranx = Math.round((Math.random ()*250));
    	rany = Math.round ((Math.random ()*250));
    }
    newpos();
    var set:Boolean=false;
    this.onEnterFrame = function() {
            if(!set) {
    	  this._x += ((ranx-this._x)/acceleration);
    	  this._y += ((rany-this._y)/acceleration);
             set=true;
            } else {
              this.onEnterFrame=null;
            }
    };
    
    drag9.onPress = function() {
    	_root.slide9.startDrag();
    	_root.slide9.swapDepths(_root.getNextHighestDepth());
    }
    drag9.onRelease = drag.onReleaseOutside = function() {
    	_root.slide9.stopDrag();
    }
    [Jasme Library (Javascript Motion Effects)] My Site
    /\/\@§†ê® §©®¡þ† /\/\@|{ê®
    There are 10 kinds of people in the world, those that understand binary and those that don't.

  5. #5
    Join Date
    Mar 2007
    Location
    Currently: New York/Philadelphia
    Posts
    2,735
    Thanks
    3
    Thanked 519 Times in 507 Posts

    Default

    The above would work. You could also test to see if the x coordinate of the MC is equal to randx (or test the y).

Bookmarks

Posting Permissions

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