Reputation: 43
We can pass data to the next view while using navigator.pushview, but the data is lost when the back button is clicked (popview).
I have views that make remote calls and I want to keep the data when the user navigates back to the view using the back button so I don't have to make a remote call again.
Is there a way to set a global variable that's accessible from all views, or a way to retain data when a user navigates back to a view using the back button?
Upvotes: 1
Views: 1524
Reputation: 11
You can declare the global variables in the main application mxml file. For example, you define a variable student in the main application, then you can access it in any other view by using FlexGlobals.topLevelApplication.student
Upvotes: 1
Reputation: 23038
You're supposed to assign your value as a property to data member of the view.
But sometimes I use data for something else (for example as a dataprovider for a List in the view) and then I create static variables in my views and store my stuff there.
Upvotes: 0
Reputation: 8875
It looks like the good way to do that is overriding the createReturnObject method in your view.
Read this for more info
Also, the data property is persisted and re-assigned when the view is re-instancied, so you can store info in it
Upvotes: 1
Reputation: 43
Ok figured it out.
I can set variables in the main application and access them from any view using
this.parentApplication.myVar;
Upvotes: 3