tags:

views:

311

answers:

3

Hi, 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 present 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

+2  A: 

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

quoo
+1: I'll add, for the OP, that learning about custom events will help you make a quantum leap in your Flex prowess.
Robusto
A: 

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

Vinothbabu
+1  A: 

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 
Amarghosh