Yordan Yanakiev
Yordan Yanakiev

Reputation: 2604

Flex : SpriteVisualElement can not add as a child Spark Label?

            var s : SpriteVisualElement = new SpriteVisualElement();
                s.graphics.beginFill( 0xFFFF00 );
                s.graphics.drawRect( 0, 0, 100, 20 );
                s.graphics.endFill();
                s.width = 100;
                s.height = 20;
            this.addElement( s ) ;

            var l : Label = new Label();
                l.text = "text";
                l.width = s.width;
                l.height = s.height;
            s.addChild( l );

The follow code seems not to working ( Flex 4.5 ).

Upvotes: 0

Views: 1682

Answers (2)

J_A_X
J_A_X

Reputation: 12847

It's not being displayed because you're not adding Label (which is a UIComponent and works with the component lifecycle) to another UIComponent that will actually instantiate it properly. Your SpriteVisualElement is not made to have UIComponents within it, it's made to have sprites which can draw itself. Label is waiting for 'invalidateDisplayList' to be called so that it can draw itself.

Either do a force draw or use a UIComponent as the container for Label.

Upvotes: 4

JeffryHouser
JeffryHouser

Reputation: 39408

The Spark Label is not a container; and therefore does not have an addElement method. I assume you're getting a compile error because of this [but you didn't tell us what your problem was].

You can wrap the label up in a container, such as a Group or SkinnableContainer and use your extra visual element as a child of the same group.

Or you could try the addChild method of the Label. It's odd to try to add Children to a component, such as Label, that is not intended as a container, though.

Upvotes: 0

Related Questions