Flex Mobile Item Renderer for Section List


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



Copy this code and paste it in your HTML
  1. <?xml version="1.0" encoding="utf-8"?>
  2. <s:IconItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009"
  3. xmlns:s="library://ns.adobe.com/flex/spark"
  4. width="100%" iconWidth="64" iconHeight="64">
  5. <fx:Script>
  6. <![CDATA[
  7.  
  8. private var _backgroundSection:Number = 0xDDDDDD;
  9.  
  10. public function set backgroundSection(value:Number):void {
  11. _backgroundSection = value;
  12. }
  13.  
  14. private var _normalLabelField:String = "label";
  15.  
  16. public function get normalLabelField():String {
  17. return _normalLabelField;
  18. }
  19.  
  20. public function set normalLabelField(value:String):void {
  21. _normalLabelField = value;
  22. }
  23.  
  24. private var _sectionField:String = "section";
  25.  
  26. public function get sectionField():String {
  27. return _sectionField;
  28. }
  29.  
  30. public function set sectionField(value:String):void {
  31. if (value == _sectionField)
  32. return;
  33.  
  34. _sectionField = value;
  35. invalidateProperties();
  36. }
  37.  
  38. /**
  39. * Change the style based on the data: section item or regular item
  40. */
  41. override public function set data(value:Object):void {
  42. if (value[_sectionField]) {
  43. labelField = _sectionField;
  44. labelDisplay.setStyle("textAlign", "center");
  45. labelDisplay.setStyle("fontWeight", "bold");
  46. } else {
  47. labelField = _normalLabelField;
  48. labelDisplay.setStyle("textAlign", "left");
  49. labelDisplay.setStyle("fontWeight", "normal");
  50. }
  51. super.data = value;
  52. }
  53.  
  54. override protected function drawBackground(unscaledWidth:Number, unscaledHeight:Number):void {
  55. super.drawBackground(unscaledWidth, unscaledHeight);
  56. //change the background if we render for a section title item
  57. if (data[_sectionField]) {
  58. graphics.beginFill(_backgroundSection, 1);
  59. graphics.lineStyle();
  60. graphics.drawRect(0, 0, unscaledWidth, unscaledHeight);
  61. graphics.endFill();
  62. }
  63. }
  64.  
  65. ]]>
  66. </fx:Script>
  67. </s:IconItemRenderer>

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

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.