Custom Layout manager scrollPositionChanged() method


/ Published in: ActionScript 3
Save to your folder(s)



Copy this code and paste it in your HTML
  1. override protected function scrollPositionChanged():void {
  2. if (!useVirtualLayout) {
  3. super.scrollPositionChanged();
  4. return;
  5. }
  6.  
  7. var g:GroupBase = target;
  8. if (!g)
  9. return;
  10. updateScrollRect(g.width, g.height);
  11.  
  12. var n:int = g.numElements - 1;
  13. if (n < 0) {
  14. setIndexInView(-1, -1);
  15. return;
  16. }
  17.  
  18. var scrollR:Rectangle = getScrollRect();
  19. if (!scrollR) {
  20. setIndexInView(0, n);
  21. return;
  22. }
  23.  
  24. var y0:Number = scrollR.top;
  25. var y1:Number = scrollR.bottom - .0001;
  26. if (y1 <= y0) {
  27. setIndexInView(0, n);
  28. return;
  29. }
  30.  
  31. var i0:int, i1:int;
  32. if (y0 < 0) {
  33. i0 = 0;
  34. i1 = yToIndex.length - 1 > g.height ? yToIndex[g.height + 1] : g.numElements - 1;
  35. setIndexInView(i0, i1);
  36. return;
  37. }
  38.  
  39. if (y1 < yToIndex.length - 1) {
  40. i0 = yToIndex[Math.floor(y0)];
  41. i1 = yToIndex[Math.ceil(y1)];
  42. } else {
  43. if (yToIndex.length - 1 - g.height < 0)
  44. i0 = 0;
  45. else
  46. i0 = yToIndex[yToIndex.length - 1 - g.height];
  47. i1 = yToIndex[yToIndex.length - 1];
  48. }
  49.  
  50. setIndexInView(i0, i1);
  51. //invalidate display list only if we have items that are not already renderered
  52. if (i0 < currentFirstIndex || i1 > currentLastIndex) {
  53. g.invalidateDisplayList();
  54. }
  55. }

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.