2 Replies Latest reply on Apr 22, 2009 10:12 AM by redcameron

    LegendItem dynamic insertion




      I'm writting and application that repopulates a legend quite frequently. I've written some code in Flex 3.0 to accomplish this. Here is the main function that does the work:

          for (var i:int = 0; i < numItems - 1; i++) {
              intensity = Math.floor(count * 256.0 / maxValue);
              if (count > 0) {
                  // Yellow (neutral) to red
                  paintColor = getHexFromRGB(255, 255 - intensity, 0);
              } else {
                  // Yellow to blue
                  paintColor = getHexFromRGB(255 + intensity, 255 + intensity, - intensity);
              signalLegend.addChild(new LegendItem());
              legendItem = signalLegend.getChildAt(i) as LegendItem;
              legendItem.label = String(roundNumber(count, 2));
              legendItem.setStyle("fill", paintColor);
              count -= perItem;


      It basically dynamically adds a LegendItem to a Legend component. The issue however is that as I add the items they render in a horizontal direction as opposed to to vertical (which is how I have it originally set). Take a look:


      mx:Legend left=0 bottom=270 id=signalLegend color=#FFFFFF direction=vertical verticalGap=3


      I'm wondering why the heck it's not aligning them properly and there really isn't much of any documentatin on this.


      Thanks in advance,