dubbeat
dubbeat

Reputation: 7857

programmatically add views to a viewstack flex

I'm trying to figure out how to in as3 (not mxml) add views to a view stack.

For example I have a view component like so

package components.screens
{
    import mx.controls.Label;
    import mx.core.UIComponent;

    public class HomeScreen extends UIComponent
    {
        private var l:Label=new Label()

        public function HomeScreen()
        {
            super();

            l.text="home";

            addChild(l)
        }

    }
}

I've being trying to add it to a viewstack in the following way

var myStack:ViewStack= new ViewStack();

mystack.addChild(homeScreen)

This does not work. Whats the correct way?

I'm aware I have to assign ID's but for now I just want to get the view in there

Upvotes: 0

Views: 3165

Answers (2)

JeffryHouser
JeffryHouser

Reputation: 39408

Can you quantify "Does not work" Are you getting a compile time error; or a run time error? Or something else?

I'm pretty sure all of the ViewStack's children must be containers; so in theory your custom component should be extending container, not UIComponent.

To quote http://livedocs.adobe.com/flex/3/langref/mx/containers/ViewStack.html

A ViewStack navigator container consists of a collection of child containers

Upvotes: 2

Samuel Neff
Samuel Neff

Reputation: 74949

You need to add the AS3-created ViewStack to some parent on the stage.

var myStack:ViewStack= new ViewStack();
mystack.addChild(homeScreen)
this.addChild(myStack);

Upvotes: 1

Related Questions