I am new to flex. I have a quick question regarding the way to implement the login feature.
I have the following components:
Currently, when the user specifies the credentials, I am going to a state where I remove the LoginPanel and add AppPanel. When he logs out, I go to the base state where I will have only LoginPanel. I have the following question:
When he logs out, what happens to the AppPanel component? Will it be there in the browser? When will it be destroyed?
I am using PureMVC as the framework. Here is the code:
<mx:State name="loginSuccessful" basedOn="">
<home:AppHome id="appHome" height="100%" width="80%" updateComplete="sendEvent(APP_HOME_ADDED);"/>
Here is the behaviour I observed:
1. First, user logs in successfully, I go to "loginSuccessful" state. When he logs out, I go to the base state, which will have only loginForm.
2. When the users clicks on the LOGOUT button in the AppHome, LOGOUT event handler is invoked.
3. When he logs out again after loggin in, LOGOUT event handler is invoked twice.
4. When he does that again, LOGOUT event handler is invoked thrice.
It goes on....It is really wierd. I think I am not doing it right. If anybody has seen this behaviour, please let me know. It will be really helpful.
If there are other ways of implementing the login feature, please let me know.
Since you say this is PureMVC it sounds like you have a Command or Mediator being registered in something each time you create the login user interface.
Where are you registering commands and mediators?
I have both the components LoginPanel and AppPanel on another component called MainPanel. This mainPanel has a Mediator which registers both the panels' mediators. I also have a LoginCommand which takes the details from the LoginPanel and authenticates.
I think I figured out the problem. I was adding the eventlistener LogOut to the AppPanel component every time I registered the AppPanel mediator. When I removed the AppPanel when the user logged out, I wasn't removing the LogOut event listener. I think I should be doing that.
Thanks for the reply Mike! It helped me.