A Flash Developer Resource Site

Results 1 to 10 of 10

Thread: [RESOLVED] [F8] We need two balls connected by a line

  1. #1
    Member
    Join Date
    Jun 2007
    Posts
    46

    [RESOLVED] [F8] We need two balls connected by a line

    We have two balls, one situated over the other, each in their own layers.

    We need to be able to drag the top ball no more than 100 pixels to the right along a straight horizontal line with no vertical travel possible.

    The second ball will not be draggable.

    A solid line is connected between the two balls as the top ball is dragged to the right.

    Any help would be so appreciated!

  2. #2
    Senior Member
    Join Date
    Oct 2004
    Posts
    2,049
    are you wanting the line to expand out with the top ball?

  3. #3
    Member
    Join Date
    Jun 2007
    Posts
    46
    Yes, that's right. For example, if the user stops the top ball at say, 65 pixels from the second ball, the line is drawn just to that 65 pixles from the second ball.

    Thanks!

  4. #4
    Senior Member
    Join Date
    Oct 2004
    Posts
    2,049
    okay - give me a few mins and I will make you a sample.

  5. #5
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,875
    give your top ball an instance name topball and your bottom ball an instance name bottomball then the following should do it:

    Code:
    var xPos:Number = topball._x;
    var draggableDistance:Number = 100;
    drawLine();
    
    
    topball.onPress = function():Void{
      	this.startDrag(true, this._x, this._y, xPos+draggableDistance, this._y);
    	
    	this.onEnterFrame = function():Void{
    		drawLine();
    	}
    }
    
    
    topball.onRelease = function():Void{
      this.stopDrag();
      delete this.onEnterframe;
    }
    
    topball.onReleaseOutside = topball.onRelease;
    
    function drawLine():Void{
    	clear();
    	_root.lineStyle(1,0,100);
    	_root.moveTo(bottomball._x, bottomball._y);
    	_root.lineTo(topball._x, topball._y);
    }
    editops just read wattsup now was gonna do it... sorry never meant to hijack ur thread
    Last edited by silentweed; 06-07-2007 at 06:21 PM.
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

  6. #6
    Member
    Join Date
    Jun 2007
    Posts
    46
    Marvelous!

    Works great. Now I'm on to figure out how it works.

    Thanks a lot silentweed.

  7. #7

  8. #8
    Member
    Join Date
    Jun 2007
    Posts
    46
    Wow, thx!

    Between silentweed's and wattsup's, I've got two working files.

    Both do exactly as I described. What I should have included was that the line between the balls was to remain between the balls, where ever the first ball was along the 100 pixel range. silentweed's does that but wattsup's line disappears when you release the mouse. Both are correct for what I described. What I needed was for the line to stay when you release.

    Still dissecting the code...

    Thx slientweed and wattsup!

  9. #9
    Senior Member
    Join Date
    Oct 2004
    Posts
    2,049
    just remove the following

    Code:
    b1.onRelease = b1.onReleaseOutside = function(){
    	delete this.onEnterFrame;
    	stopDrag();
    	//clear(); <<<--------------------remove this
    }

  10. #10
    Flashmatics silentweed's Avatar
    Join Date
    Mar 2005
    Location
    London, UK
    Posts
    4,875
    yw glad u got it sorted
    Flashmatics | Flashmatics Library (free downloads)
    -----------------------------------------------------
    Latest Projects:
    The Dead Room | Are You Smarter | Prison Break (Frame A Friend) | Beck's Fusions | The 24 Experience

    -----------------------------------------------------
    Flash Certified Developer

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