title: Viewstack accessing
body: <p>Hello with the help of Brian i have this alomost working but im missing something that doesnt let it work 100%.</p>
  
  <p>When i trace this i will get a -1 on the command panel even i login using any user.
  I want that if a user login that depending their userRole the viewstack goes to their view.</p>
  
  <p>Below you will see the code i have.
  Any more one can help please :(</p>
  
  <pre><code>&lt;mx:ViewStack id="parentStack" width="1280" height="768"&gt;
      &lt;s:NavigatorContent id="loginVS" width="100%" height="100%" label="Login"&gt;
          &lt;forms:MainSiteForm id="mainForm" horizontalCenter="0" verticalCenter="0"/&gt;
      &lt;/s:NavigatorContent&gt;
      &lt;s:NavigatorContent id="adminVS" width="100%" height="100%" label="Admin"&gt;
          &lt;s:ModuleLoader url="views/Administrator.swf"/&gt;
      &lt;/s:NavigatorContent&gt;
      &lt;s:NavigatorContent id="salesVS" width="100%" height="100%" label="Sales"&gt;
      &lt;/s:NavigatorContent&gt;
      &lt;s:NavigatorContent id="designersVS" width="100%" height="100%" label="Designers"&gt;
      &lt;/s:NavigatorContent&gt;
      &lt;s:NavigatorContent id="retailersVS" width="100%" height="100%" label="Retailers"&gt;
      &lt;/s:NavigatorContent&gt;
  &lt;/mx:ViewStack&gt;
  
  &lt;fx:Script&gt;
          &lt;![CDATA[
              import mx.containers.ViewStack;
              import mx.controls.Alert;
              //import mx.core.Container;
              import mx.core.FlexGlobals;
              import mx.validators.Validator;
  
              [Bindable]
              private var validatorArr:Array;
              private var loader:URLLoader;
              private var externalXML:XML;
  
              /**
               * Initialization method
               */
              public function init():void {
                  // Add validators to array for validating all at one time
                  validatorArr = new Array();
                  validatorArr.push(useridValidator);
                  validatorArr.push(passwordValidator);
              }
  
              /**
               * User's information checking
               * based on the inputted data
               */
              public function loginCheck():void  {
                  // Starting to validate
                  var errorArr:Array = Validator.validateAll(validatorArr)
                  // if the error array contain any data, =&amp;gt; error
                  var isValid:Boolean = errorArr.length == 0;
  
                  if (isValid) {
                      // Load user data
                      doLogin();
                  }
              }
  
              private function doLogin():void {
                  // Point to the data file's path
                  var request:URLRequest = new URLRequest("data/Users.xml");
  
                  loader = new URLLoader();
                  try {
                      loader.load(request);
                  } catch (error:SecurityError) {
                      trace("A SecurityError has occurred.");
                  }
  
                  // If error, go to errorHandler function
                  loader.addEventListener(IOErrorEvent.IO_ERROR, errorHandler);
                  // once the load action was complated, go to loaderCompleteHandler() for
                  // checking user information
                  loader.addEventListener(Event.COMPLETE, loaderCompleteHandler);
              }
  
              private function loaderCompleteHandler(event:Event):void {
                  var logged:Boolean = false;
                  try {
                      // Convert data into E4X class for easy access to elements
                      externalXML = new XML(loader.data);
  
                      // Loop through the user list to check
                      // if the inputted user id and password are valid
                      for each (var user:XML in externalXML.elements()) {
                          if (user.userID == userID.text &amp;&amp; user.userPW == userPW.text) {
                              // user has an valid account
                              logged = true;
                              // Don't need to continue
                              break;
                          }
                      }
                      if (logged) {
                          // Redirect user function
                          var indexArr:Array = new Array("Login", "Admin", "Sales", "Designers", "Retailers");
                          var stackIndex:int = indexArr.indexOf(user.userRole);
                          FlexGlobals.topLevelApplication.parentStack.selectedIndex = stackIndex;
                          trace(stackIndex);
                          //Alert.show('Congratulation, you logged in!', 'Information');
                      } else {
                          Alert.show('User ID or Password is not correct, please try again!', 'Error');
                      }
  
                  } catch (e:TypeError) {
                      trace("Could not parse the XML file.");
                  }
              }
              private function errorHandler(e:IOErrorEvent):void {
                  Alert.show("Had problem loading the XML File.");
              }
  
          ]]&gt;
      &lt;/fx:Script&gt;
  </code></pre>
  
  <p>--------------------------------------------------XML File</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;users&gt;
      &lt;user&gt;
          &lt;userID&gt;admin&lt;/userID&gt;
          &lt;userPW&gt;password&lt;/userPW&gt;
          &lt;userRole&gt;Admin&lt;/userRole&gt;
      &lt;/user&gt;
      &lt;user&gt;
          &lt;userID&gt;sales&lt;/userID&gt;
          &lt;userPW&gt;password&lt;/userPW&gt;
          &lt;userRole&gt;Sales&lt;/userRole&gt;
      &lt;/user&gt;
      &lt;user&gt;
          &lt;userID&gt;designer&lt;/userID&gt;
          &lt;userPW&gt;password&lt;/userPW&gt;
          &lt;userRole&gt;Designers&lt;/userRole&gt;
      &lt;/user&gt;
      &lt;user&gt;
          &lt;userID&gt;buyer&lt;/userID&gt;
          &lt;userPW&gt;password&lt;/userPW&gt;
          &lt;userRole&gt;Retailers&lt;/userRole&gt;
      &lt;/user&gt;
  &lt;/users&gt;
  </code></pre>