Flex: View Stack Navigator
I have a component mxml file in which i have a view stack, on click of a button i navigate to the first child, now i need to navigate to the second child during onclick of a button pr开发者_StackOverflow中文版esent in the second child. All the childs are component files included within the view stack. How could this be done, Sample code is present below,
--------------------Application.mxml---------------------
<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" >
<mx:Script>
<![CDATA[
private function loadScreen():void
{
navigationViewStack.selectedChild=id_offering;
}
]]>
</mx:Script>
<mx:Button label="Save" click="loadScreen();"/>
</mx:Canvas>
<mx:ViewStack id="navigationViewStack" width="100%" height="100%">
<components:dashboard id="id_dashboard" label="Dashboard" />
<components:offering id="id_offering" label="Offering" />
<components:IssueSec id="id_issueSec" label = "Issues"/>
</mx:ViewStack>
-------------------------Ends--------------------------------------
Now in my offering.mxml file if i try to access navigationViewStack i am getting an error stating 'Access of undefined property navigationViewStack.
Help me on how to access the view stack from my component mxml file.
Thanks!
Cheers, Deena
Offering.mxml does not have access to navigationViewStack as it is a property inside your Application.mxml file. You'll need to dispatch an event from inside of offering.xml, Application.mxml will listen for that event, and handle it by switching to the appropriate view stack element.
If you're not familiar with custom events, read this:
http://livedocs.adobe.com/flex/3/html/help.html?content=createevents_3.html
Custom event is the correct and appropriate way to go; if you want a quick and dirty solution that will eventually become difficult to maintain as your code base grow, you can try this from the button click handler in the Offering.mxml
:
ViewStack(this.parent).selectedIndex = 2; //2 for IssueSec
Custom events is the answer for your question. Its simple have a look at this example
http://flexblog.faratasystems.com/2007/02/26/event-driven-programming-in-flex-with-custom-events
精彩评论