A Flash Developer Resource Site

Results 1 to 6 of 6

Thread: [RESOLVED] Activate scroll only towards end of scrollbar?

  1. #1
    Member
    Join Date
    Jul 2008
    Posts
    73

    resolved [RESOLVED] Activate scroll only towards end of scrollbar?

    I have a scrollbar that scrolls left or right when the cursor is moved either side of the central x coordinate. I've been trying to change it so the scroll only activates when the cursor is towards the far right hand side (ie x>75%) or towards the far left hand side (x<25%) of the scrollbar, leaving the central 50% of the scrollbar inactive. How could I go about this?

    Code:
    function scrolling() {
    	_root.onEnterFrame = function() {
    
    		container_mc._x += Math.cos(((mask_mc._xmouse)/mask_mc._width)*Math.PI)*15;
    
    		if (container_mc._x>mask_mc._x) {
    			container_mc._x = mask_mc._x;
    		}
    
    		if (container_mc._x<(mask_mc._x-(container_mc._width-mask_mc._width))) {
    			container_mc._x = mask_mc._x-(container_mc._width-mask_mc._width);
    		}
    	};
    }
    The .fla is here http://board.flashkit.com/board/showthread.php?t=808636

  2. #2
    var x:Number = 1; x /= 0;
    Join Date
    Dec 2004
    Posts
    549
    _x+=(_xmouse-(_x-(_width/4)*(_xmouse<_x)+(_width/4)*(_xmouse>_x)))*(Math.abs(_xmouse-_x)>_width/4);

    That should work. If you want me to explain how it works, I'd be happy to.

    -Zippy Dee


    //EDIT------
    In fact, you could make that even a little bit shorter:
    _x+=(_xmouse-(_x+(_width/4)*((_xmouse>_x)-(_xmouse<_x))))*(Math.abs(_xmouse-_x)>_width/4);
    Last edited by ZippyDee; 01-21-2010 at 07:30 AM.
    Z¡µµ¥ D££

    Soup In A Box

  3. #3
    Member
    Join Date
    Jul 2008
    Posts
    73
    Thanks Zippy. Yes please, if you could. I cannot get it to work.

    I exchanged this

    Code:
    container_mc._x+=(_xmouse-(mask_mc._x-(mask_mc._width/4)*(_xmouse<mask_mc._x)+(mask_mc._width/4)*(_xmouse>mask_mc._x)))*(Math.abs(_xmouse-mask_mc._x)>mask_mc._width/4);
    with

    Code:
    container_mc._x += Math.cos(((mask_mc._xmouse)/mask_mc._width)*Math.PI)*15;

  4. #4
    var x:Number = 1; x /= 0;
    Join Date
    Dec 2004
    Posts
    549
    It should work fine. It's written assuming the mask_mc._x is in the center of the movieclip.


    I should have used x1 and x2 in that equation, but you understood and used the right movieclips.
    Basically this single equation is equivalent to this code:
    Code:
    if(Math.abs(_xmouse-x1)>_width/4){
    	if(_xmouse<x1){
    		x2+=_xmouse-(x1-_width);
    	}
    	if(_xmouse>x1){
    		x2+=_xmouse-(x1+_width);
    	}
    }
    In case you don't already know, if you use a boolean in an equation, Flash automatically reads "true" as "1" and "false" as "0". That's why you're able to make all that into one equation.

    You might also want to try the code I just posted, just to see if that works any better.
    Z¡µµ¥ D££

    Soup In A Box

  5. #5
    var x:Number = 1; x /= 0;
    Join Date
    Dec 2004
    Posts
    549
    If that still doesn't work, try this:

    Code:
    container_mc._x+=(mask_mc._xmouse-(mask_mc._width/2-(mask_mc._width/4)*(mask_mc._xmouse<mask_mc._width/2)+(mask_mc._width/4)*(mask_mc._xmouse>mask_mc._width/2)))*(Math.abs(mask_mc._xmouse-mask_mc._width/2)>mask_mc._width/4);
    Z¡µµ¥ D££

    Soup In A Box

  6. #6
    Member
    Join Date
    Jul 2008
    Posts
    73
    Great, it's working. Thanks Zippy. To slow down the speed I just added *1/10 to the end too. Ps 'Way Into my Head' - nice song!

Tags for this Thread

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