1 Reply Latest reply on Apr 26, 2007 4:18 AM by mikeshank

    Custom LegendItem

    mikeshank
      Hi
      How do I access the dataProvider data for each child when overriding the createChildren() method?

      public class CpPiechartLegendItem extends LegendItem
      {
      public function CpPiechartLegendItem()
      {
      super();
      }

      override protected function measure():void {
      super.measure();
      }

      override protected function createChildren():void {
      super.createChildren();
      trace(super.legendData); // throws error

      // this will give me data for myProperty at index 0, but how do I iterate over dataProvider to get the data for the corresponding child?
      trace(super.source.dataProvider[0].myProperty);
      }

      protected override function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void{
      super.updateDisplayList(unscaledWidth, unscaledHeight);

      }
      }
        • 1. Re: Custom LegendItem
          mikeshank Level 1
          Well, if anyone is interested here's my hack to get this to work.
          I set a counter var and increment with each iteration of createChildren. I'm sure there's a more effecient or "correct" way, so if anyone knows please share.

          public class CpPiechartLegendItem extends LegendItem
          {
          public static var item_index:Number = 0;

          public function CpPiechartLegendItem()
          {
          super();
          }

          override protected function measure():void {
          super.measure();
          }

          override protected function createChildren():void {
          super.createChildren();
          trace(super.source.dataProvider[item_index-1].myProperty;);
          }

          protected override function updateDisplayList(unscaledWidth:Number, unscaledHeight:Number):void{
          super.updateDisplayList(unscaledWidth, unscaledHeight);
          }
          }