List Item Renderer for Section Tile List


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



Copy this code and paste it in your HTML
  1. /**
  2.  * Section Title font size
  3.  */
  4. [Style(name="sectionFontSize", type="Number", format="Length", inherit="no")]
  5.  
  6. public class ListItemRenderer extends IconItemRenderer {
  7.  
  8. private var _backgroundSection:Number = 0xDDDDDD;
  9.  
  10. public function set sectionFontSize(value:int):void {
  11. setStyle("sectionFontSize", value);
  12. }
  13.  
  14. public function set backgroundSection(value:Number):void {
  15. _backgroundSection = value;
  16. }
  17.  
  18. private var _sectionLabel:String = "section";
  19.  
  20. public function set sectionLabel(value:String):void {
  21. if (value == _sectionLabel)
  22. return;
  23.  
  24. _sectionLabel = value;
  25. invalidateProperties();
  26. }
  27.  
  28. private var _normalLabelField:String = "label";
  29.  
  30. public function set normalLabelField(value:String):void {
  31. _normalLabelField = value;
  32. }
  33.  
  34. /**
  35. * Change the style based on the data: section item or regular item
  36. */
  37. override public function set data(value:Object):void {
  38. if (value) {
  39. if (value[_sectionLabel]) {
  40. label = value[_sectionLabel];
  41. labelDisplay.setStyle("textAlign", "center");
  42. labelDisplay.setStyle("fontWeight", "bold");
  43. labelDisplay.setStyle("fontSize", getStyle("sectionFontSize"));
  44. iconWidth = 0;
  45. } else {
  46. iconWidth = iconHeight;
  47. label = value[_normalLabelField];
  48. labelDisplay.setStyle("fontSize", getStyle("fontSize"));
  49. labelDisplay.setStyle("textAlign", "left");
  50. labelDisplay.setStyle("fontWeight", "normal");
  51. }
  52. }
  53. super.data = value;
  54. }
  55.  
  56. /**
  57. * Change the background color for section items
  58. */
  59. override protected function drawBackground(unscaledWidth:Number, unscaledHeight:Number):void {
  60. super.drawBackground(unscaledWidth, unscaledHeight);
  61.  
  62. if (data[_sectionLabel]) {
  63. graphics.beginFill(_backgroundSection, 1);
  64. graphics.lineStyle();
  65. graphics.drawRect(0, 0, unscaledWidth, unscaledHeight);
  66. graphics.endFill();
  67. }
  68. }
  69. }

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.