Custom Layout manager updateDisplayList() method - non virtual


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



Copy this code and paste it in your HTML
  1. private function updateNonVirtual(containerWidth:Number, containerHeight:Number):void {
  2. var layoutTarget:GroupBase = target;
  3. if (!(layoutTarget as DataGroup).dataProvider || (layoutTarget as DataGroup).dataProvider.length == 0)
  4. return;
  5.  
  6. if (!_containerWidth)
  7. _containerWidth = containerWidth;
  8. if (!_containerHeight)
  9. _containerHeight = containerHeight;
  10.  
  11. var x:Number = 0;
  12. var y:Number = 0;
  13. var maxWidth:Number = 0;
  14. var maxHeight:Number = 0;
  15. var elementWidth:Number, elementHeight:Number, prevElementHeight:Number;
  16.  
  17. //add some extra rows after the current view
  18. y = 0;
  19. var count:int = layoutTarget.numElements;
  20. var element:ILayoutElement;
  21.  
  22. for (var i:int = 0; i < count; i++) {
  23. // get the current element, we're going to work with the
  24. // ILayoutElement interface
  25. element = layoutTarget.getElementAt(i);
  26. // Resize the element to its preferred size by passing
  27. // NaN for the width and height constraints
  28. element.setLayoutBoundsSize(NaN, NaN);
  29. if (element["data"] && _sectionLabel in element["data"]) {
  30. elementWidth = containerWidth;
  31. elementHeight = _sectionHeight;
  32. } else {
  33. elementWidth = _columnWidth;
  34. elementHeight = _tileHeight;
  35. }
  36. element.setLayoutBoundsSize(elementWidth, elementHeight);
  37.  
  38. // Would the element fit on this line, or should we move
  39. // to the next line?
  40. if (x + elementWidth > containerWidth) {
  41. x = 0;
  42. //move to the next row
  43. y += prevElementHeight + _verticalGap;
  44. }
  45. // Position the element
  46. element.setLayoutBoundsPosition(x, y);
  47. prevElementHeight = elementHeight;
  48. // Update the current position, add the gap
  49. x += elementWidth + _horizontalGap;
  50. }
  51. // Scrolling support - update the content size
  52. layoutTarget.setContentSize(containerWidth, y);
  53. }

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.