Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do you limit scrolling?

Status
Not open for further replies.

thenewa2x

Programmer
Dec 10, 2002
349
US
I've wrote a listener to scroll a window that has been masked. So far I have come up with this:

Code:
// Attach mouse wheel scroll listeners.
_global.mWheel = new Object ( );
        mWheel.onMouseWheel = function ( delta:Number )
		{
			// Recalculate delta.
			delta *= 3;
			
			// Shift being held down?
			if ( Key.getCode( ) == 16 )
			{
				// Speed up more.
				delta *= 2;
			}
			
			// Get new position.
			newPos = _root.catpg._y + delta;
			
			// Scrolling Down?
			if ( newPos < _root.catpg._y )
			{
				// Reached end of page?
				if ( ( _root.catpg._height - newPos ) )
					;
				trace( _root.catpg._height - newPos );
			}
			
			// Scrolling up?
			else
			{
			}
			
			_root.catpg._y = newPos;
		}
Mouse.addListener( _global.mWheel );

The scrolling and scrolling acceleration (16 = Shift) works but I don't know how to limit it. I want to prevent it from scrolling beyond the beginning and ending of the clip that was masked. Please let me know if I missed any information I should have provided.

Thanks.

---------------------------------------
TINSTAAFL, which is why I contribute.
 
Just FYI, the height of the content box is dynamic, it changes depending on the contents. The mask size is constant however, it is height: 290, width: 549 and it is called [tt]_root.maskCat[/tt].

---------------------------------------
TINSTAAFL, which is why I contribute.
 
Well I figured out how to prevent it from going too far up.

Code:
// Attach mouse wheel scroll listeners.
_global.mWheel = new Object ( );
        mWheel.onMouseWheel = function ( delta:Number )
		{
			// Recalculate delta.
			delta *= 3;
			
			// Shift being held down?
			if ( Key.getCode( ) == 16 )
			{
				// Speed up more.
				delta *= 2;
			}
			
			// Get new position.
			newPos = _root.catpg._y + delta;
			
			// Scrolling Down?
			if ( newPos < _root.catpg._y )
			{
				// Too low?
				if ( ( Math.abs( newPos ) + _global.defaultY ) > _root.catpg._height )
				{
					//
				}
			}
			
			// Scrolling up?
			else
			{
				// Too high up?
				if ( newPos > _global.defaultY )
					newPos = _global.defaultY;
			}
			
			_root.catpg._y = newPos;
		}
Mouse.addListener( _global.mWheel );

Now I just need to know how to prevent it from scrolling down too far.

---------------------------------------
TINSTAAFL, which is why I contribute.
 
Ok, nvm. I think I figured it out. Now I just have to fix another glitch...

Heh.

---------------------------------------
TINSTAAFL, which is why I contribute.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top