Search code examples
flashapache-flexflex4flash-builderflashbuilder4

How do I pass data between ViewNavigators in Flash Builder 4.5 Burrito


I'm giving it a try and it happens that I'm having a hard time figuring out how to pass data between ViewNavigator in a TabbedMobileApplication.

<s:TabbedMobileApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
               xmlns:s="library://ns.adobe.com/flex/spark">
    <fx:Declarations>
    </fx:Declarations>

    <s:ViewNavigator id="nav1" label="Nav1" firstView="views.Nav1Home" width="100%" height="100%"/>
    <s:ViewNavigator id="nav2" label="Nav2" firstView="views.Nav2Home" width="100%" height="100%"/>

</s:TabbedMobileApplication>

How can I pass data between nav1 and nav2? I know how to do it in between navigation views.

Thanks, B.


Solution

  • Unless I'm missing something here, what you're going to want to do is and a script block in here and listen to your ViewNavigators for events. Then in th handler for the event, call a public functions on the targeted ViewNav.

    <s:TabbedMobileApplication xmlns:fx="http://ns.adobe.com/mxml/2009" 
                   xmlns:s="library://ns.adobe.com/flex/spark" creationComplete="init()">
        <fx:Declarations>
        </fx:Declarations>
    
        <fx:script><![CDATA[
            private function init():void{
                   nav1.addEvenListener(CustomEvent.DATA, onData);
            }
    
            private function onData(ev:CustomEvent):void{
                   nav2.setData(ev.data);
            }
        ]]></fx:script>
    
    
    
        <s:ViewNavigator id="nav1" label="Nav1" firstView="views.Nav1Home" width="100%" height="100%"/>
        <s:ViewNavigator id="nav2" label="Nav2" firstView="views.Nav2Home" width="100%" height="100%"/>
    
    </s:TabbedMobileApplication>