views:

198

answers:

1

i try to make a login sistem in flex, and my app looks like this:

i have a main.mxml. when the app loads, a function named "start" is called. it verifies if the user is logged in or not. if "true" the user is redirected to a dashboard, if "false", a component named login is loaded.

my login.mxml component has 2 input boxes (user & pass) and a "Submit" button. when the button is pressed a function named "send_login" sends the user and the pass values to the server.

My problem sounds like this: when i press the Submit button in my login component, after user and pass are sended... i want to call again the "start" function from my main.mxml to check again if the user is logged in or not...

i need some kind of as2 "_root"

this is how my code looks:

main.mxml

public function start():void {
  currentState="Start";
  loginstatus();
 }

login.mxml

private function send_login(event:Event):void {

 ... bla bla send user and pass....
 scriptLoader.addEventListener(Event.COMPLETE, handleLoadSuccessful);
}

private function handleLoadSuccessful(evt:Event):void { 

 trace("Data sent.");
  start();  <-- HERE i want to call the function from main.mxml
}

any help is welcomed!

A: 

too late guys, i found the solution :D

import mx.core.FlexGlobals; 

private function handleLoadSuccessful(evt:Event):void { 
    trace("Data sent.");
    FlexGlobals.topLevelApplication.start();  
}
hyper
It's bad practice to use global variables as a communication channel. You should use events instead.
PeZ