As usual I am showing my Flex naivete with my questions. So, what's another one...
Is there a way to have the variables I set in a pop-up window (think login), persist and be accessible even when that pop-up is closed?
For example, I have an application that uses a pop-up login window to control access to the application. The user supplies userid, password and role. When the user is authenticated, the pop-up closes and a viewstack is displayed based on the results of the role selected in the pop-up.
All that works just fine. Now, I want to display the userid in the components within the viewstack. For example I want to display a welcome message based on the userid. In ColdFusion, I would just use a session variable. However, I believe there is some way to call any variable in the application as long as the movie is still running.
I cant seem to figure out how to do this. Any help would be appreciated.
You can set a variable in the application.
Code in the popup:
private var app:Object = mx.core.Application.application;
app.myVar = myPopUpVarValue;
Or you can dispatch a custom event that has the data as a property you define in the custom event. This is the preferred way of doing it (lloosely coupled app) but in this case you need to add the event listener to systemManager, not to the application, as popups are in a different display list below systemManager.
Here is my Flex cookbook post on custom events:
It is more work, so you might want to go with option 1 above (mx.core.Application.application), but long-term you want to be using custom events.
If this post answered your question or helped, please mark it as such.