This content has been marked as final. Show 7 replies
You could pass a reference to the user object to the TitleWindow.
But a better approach would be to put the user property in a model, so you can access it from anywhere.
Have a look at Cairngorm, Pure MVC and some other frameworks.
How do I pass a reference to the user object to theTitleWindow?
I know about Cairngorm. But this project is small and therfore I have choosen not to use Cairngorm for this project
Let's assume you have a parent of class MyParentClass.mxml
You would have a corresponding property in the LoginTitleWindow MXML:
public var parent:MyParentClass;
This property will be set by the parent when it creates the popup:
loginTitleWindow.parent = this;
I created a very simple sample based on Karl's suggestions. You can see how the instance of the main application is passed to the another object (window) in initApp() function. You can also see how the markUserAuthenticated() function is invoked from another window launched using the reference passed.
Again it's better to create a singleton object of some other class and then store the login status of the user in that object instance rather than passing the reference of the Application and the invoking the method.
Just my opinion :)
Please check out the sample below.
Hope this helps.
You are absolutely right. I should use a singleton to hold the data instead of all the data parsing between the modules.
Much cleaner and much easier.
This is what I pointed out when I said, use Cairngorm.
You are free to use in Cairngorm only those things you need.
The ModelLocator in Cairngorm is a singleton.
Yes I know now. I did not think of just use the ModelLocator.
But that is ofcause the way to get.