开发者

Flex Hero Mobile, sharing data when popping views

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 naviga开发者_StackOverflowtes back to a view using the back button?


Ok figured it out.

I can set variables in the main application and access them from any view using

this.parentApplication.myVar;


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


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


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜