Return to Snippet

Revision: 48788
at July 9, 2011 01:07 by mcorlan


Initial Code
override protected function scrollPositionChanged():void {
	if (!useVirtualLayout) {
		super.scrollPositionChanged();
		return;
	}
		
	var g:GroupBase = target;
	if (!g)
		return;     
	updateScrollRect(g.width, g.height);
	
	var n:int = g.numElements - 1;
	if (n < 0) {
		setIndexInView(-1, -1);
		return;
	}
	
	var scrollR:Rectangle = getScrollRect();
	if (!scrollR) {
		setIndexInView(0, n);
		return;    
	}
	
	var y0:Number = scrollR.top;
	var y1:Number = scrollR.bottom - .0001;
	if (y1 <= y0) {
		setIndexInView(0, n);
		return;
	}

	var i0:int, i1:int;
	if (y0 < 0) {
		i0 = 0;
		i1 = yToIndex.length - 1 > g.height ? yToIndex[g.height + 1]  : g.numElements - 1;
		setIndexInView(i0, i1);
		return;	
	}
		
	if (y1 < yToIndex.length - 1) {
		i0 = yToIndex[Math.floor(y0)];
		i1 = yToIndex[Math.ceil(y1)];
	} else {
		if (yToIndex.length - 1 - g.height < 0)
			i0 = 0;
		else
			i0 = yToIndex[yToIndex.length - 1 - g.height];
		i1 = yToIndex[yToIndex.length - 1];
	}

	setIndexInView(i0, i1);
	//invalidate display list only if we have items that are not already renderered
	if (i0 < currentFirstIndex || i1 > currentLastIndex) {
		g.invalidateDisplayList();
	}
}

Initial URL
http://corlan.org/?p=2987

Initial Description

                                

Initial Title
Custom Layout manager scrollPositionChanged() method

Initial Tags

                                

Initial Language
ActionScript 3