Question

I am looking to get access to individual legend items in actionscript (a Legend Item being the label and coloured block identifying a chart series). Does anyone know of a property of the Legend or Chart that gives access to all of the currently displayed LegendItems in a Legend?

I know this is possible by using LegendMouseEvents, as the events give access to the LegendItem that has been clicked/rolled over ect. However, I cannot rely on an event in this case.

My last resort is to hack up a custom legend, but this will take time (which I don't particularly have) so I just thought I would appeal to the SO community first!

Thanks guys

Was it helpful?

Solution

A legend is a container, so you should be able to do as shown in the code below:

var currentLegendItem:LegendItem;

for (var i:int = 0; i < legend.numChildren; i++) {
currentLegendItem = LegendItem(legend.getChildAt(i));
}

OTHER TIPS

I tried the solution proposed by Double but, for some reason, it didn't work (though it really should have). I'll have to see about trying to get it to work later. Thought I'd post this alternative solution in case anyone else is having the same trouble.

I managed to find another solution (though I'm not sure if it would help the OP in their situation). I only needed to influence my legendItems on creation so performed an action on the legend's childAdd event and did what I needed to do to the legendItem then.

private function legendItemAdded(event:ChildExistenceChangedEvent):void {
   var legendItem:LegendItem = event.relatedObject as LegendItem;

   // do what you want with it
}

.........

<mx:Legend id="myLegend"
dataProvider="{myDP}"
borderStyle="solid"
stroke=""
borderThickness="0"
top="0" bottom="20"
childAdd="legendItemAdded(event)"/>
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top