1 Reply Latest reply on Dec 22, 2008 8:14 AM by monkeyden.com

    Programmatically Manipulating the view

    monkeyden.com
      I'm trying to add some children and change the selectedIndex of an MXML ViewStack from an AS3 class, but my changes aren't showing. If you're familiar with PureMVC, this is in the mediator class. Here is the code:

      var viewStack:ViewStack = application.getChildByName("mainViewStack") as ViewStack;
      var container:Canvas = viewStack.getChildByName("mainBox") as Canvas;

      var mainNav:MainNav = new MainNav();
      mainNav.id = "mainNav";
      mainNav.x = -500;
      mainNav.y = 150;

      var welcome:WelcomeScreen = new WelcomeScreen();
      welcome.id = "welcomeScreen";
      welcome.x = 500;
      welcome.y = 500;

      container.removeAllChildren();
      container.addChildAt(mainNav, 0);
      container.addChildAt(welcome, 1);
      viewStack.selectedIndex = 1;
        • 1. Re: Programmatically Manipulating the view
          monkeyden.com Level 1
          To simplify the example, I removed all of the addChild stuff, and put the children in the MXML like so:

          <mx:ViewStack id="mainViewStack" creationPolicy="all" width="100%" height="100%">
          <components:LoginPanel id="loginPanel" title="Login" horizontalCenter="0" verticalCenter="0" />
          <mx:HBox id="mainBox" name="mainBox" width="100%" height="100%">
          <navigation:MainNav id="mainNav" x="500" y="150"/>
          <components:WelcomeScreen x="500" y="500"/>
          <mx:Text text="Hello" color="#ffffff" x="500" y="500"/>
          </mx:HBox>
          </mx:ViewStack>

          So now the AS code simply looks like this:

          var viewStack:ViewStack = application.getChildByName("mainViewStack") as ViewStack;
          viewStack.selectedIndex = 1;

          The MainNav and WelcomeScreen appear for a split second and LoginPanel reappears. It seems something is modifying it. I have done a search for selectedIndex throughout my code and this is the only place it appears. Is there something about the rendering I'm missing?

          Thanks for any tips!