Appcelerator Titanium: How to use the OnLoad event of a Window?

advertisements
mainWin.pageLoad=false;
mainWin.addEventListener('load', function(e) {
  if(mainWin.pageLoad) {
    mainWin.open();
     } else {
      mainWin.close();
      var LoginWindow = Titanium.UI.createWindow({
        title : 'Login',
        url:'Login.js'
      });
   LoginWindow.open();
  }
});

This is my app.js file. If the pageLoad variable holds the boolean value true, then i need to navigate to mainWin {Which is the current Window} else i need to go to Login Page.


    var LoginWindow = Titanium.UI.createWindow ({
      backgroundColor:'#1E563F',
      url:'Login.js',
    });

    mainWin.addEventListener('open', checkPage);
        mainWin.pageLoad = false;

        function checkPage() {
           if(mainWin.pageLoad) {
             mainWin.open();
           } else {
             mainWin.close();
             LoginWindow.open();
           }
        }

  mainWin.open();

This should work....