Sam
Sam

Reputation:

Actionscript and ViewStack = Cannot access a property or method of a null object reference

I'm writing a flex program in an OO manner and I've got to the point of creating a ViewStack to hold various panels. My problem is that when I add a panel to the ViewStack it throws the aforementioned error. No doubt the answer is pretty obvious so here's the constructor for the manager class that holds my ViewStack.

stack = new ViewStack();
loginPanel = new LoginPanel;
regPanel = new RegisterPanel;
stack.creationPolicy = "all";
stack.addChild(loginPanel);
stack.currentState = "loginPanel";

Upvotes: 2

Views: 1506

Answers (1)

Eric Belair
Eric Belair

Reputation: 10692

I'm not sure why you are setting the currentState property of the ViewStack. Are you trying to select that child? If so, try using the selectedChild property instead. This should work:

{
    stack = new ViewStack();

    loginPanel = new LoginPanel();

    regPanel = new RegisterPanel();

    stack.creationPolicy = "all";

    stack.addChild(loginPanel);

    stack.selectedChild = loginPanel;
}

Upvotes: 3

Related Questions