views:

711

answers:

5

I'm dynamically inserting LegendItems into a Legend using the following code:

signalLegend.removeAllChildren();
signalLegend.direction = "vertical";
for (var i:int = 0; i < numItems - 1; i++) {
    signalLegend.addChild(new LegendItem());
    legendItem = signalLegend.getChildAt(i) as LegendItem;
    legendItem.label = "Title here";
    legendItem.setStyle("fill", theColour);
}

While the Legend direction is set as vertical, all the items are appearing horizontally.

Very annoying.

A: 

use the labelPlacement style

heri0n
A: 

This seems to be a bug. The children of the Legend control are placed wrong, if you add them at runtime. Set the direction to "horizontal" and the items will appear vertically. :-)

splash
A: 

Hi, I'm also facing this problem, and am wondering if you found a fix/workaround?

Magick
A: 

Ok, I found a solution.

                <mx:Legend id="nhLeg"
                       updateComplete="LegendPosition()"
                       direction="vertical"
                       width="80%"/>

And then in the LegendPosition() function:

            private function LegendPosition():void
        {

            nhLeg.direction="vertical";
        }
Magick
A: 

Magick that solution is very bad because nhLeg.direction="vertical"; runs invalidProperities on nhLeg and invalidProperitie dispatch update event so that construction loop your code

tdrozdz