This content has been marked as final. Show 5 replies
The short answer is "yes". For example, if you have a public function called "test" that's on a child of the view stack in your main application:
<mx:Application ... >
<local:SomeChild id="page1" ... />
<local:AnotherChild id="page2" ... />
You can directly reference page2.test() from the main application.
However, the ViewStack doesn't normally create all of its children until you navigate to them. So you function may not exist or may use undefined data. Set creationPolicy="all" on the ViewStack to have it create all the children at once.
Now, my question: why would you want to do that? There are some good reasons to do it, but there may be better ways to achieve what you want.
I assume the 'pages' you're refering to are components?
You should just be able to say:
I think by default you will only be able to access the components that are in the currently shown stack container and that setting creationPolicy to "all" should eliminate that issue.
Thanks Pete and Mac
I'm using a applicationControlBar to run functions on the child pages. If you have a better way please let me know.
but there may be better ways to achieve what you want.
I have the same problem. I use a ViewStack in which there are views. In a search view, I retrieve a list of results from Java backend. Now, I want to pass these results to another view, say result view.
Basically I do something like this in the search view :
main.viewResult.resultList = results;
But at runtime (just the first time) an error occurs :
Error #1009: Cannot access a property or method of a null object reference
the ViewStack doesn't normally create all of its children until you navigate to them.
That's why error message #1009 is diplayed only the first time... I try to use creationPolicy="all" but I have other issues using it and it seems not to be a good practise.
I'd like to know if there's a better way to pass variables through differents views of a ViewStack... like sharing data or whatever ?
One approach is to keep common data at the ViewStack's level and pass a reference to that common data to each child. For example, you can give each child a property called "commonData" and then do something like:
private var myData: Object; //data held at the ViewStack's level
This is the general idea. It's not very useful as is.