1 Reply Latest reply on Jun 10, 2010 12:01 PM by flairjax

    Navigation from within a custom component ???

    Whitetimer Level 1

      Hi All

       

      I am working on a new project in Flex 4 and i have a Viewstack on my main page.  Then i have 6 custom components in the viewstack, the first being the home page.  In this homepage custom component i have linkbuttons which i want the user to click on to navigate the viewstack ..

       

      So what would be the best way to do this ?

       

                               <fx:Script>

                                    <![CDATA[

       

                                         ]]>

                               </fx:Script>

       

                     <mx:ViewStack id="vs" width="800" height="1000">
                          <s:NavigatorContent width="100%">
                               <v:VHome id="vHome" />
                                              <v:VHome id="vAbout" />
                                              <v:VHome id="vShop" />
                                              <v:VHome id="vProducts" />
                                              <v:VHome id="vSupport" />
                                              <v:VHome id="vContact" />
                               </s:NavigatorContent>
                     </mx:ViewStack>
      
      
      <s:Group xmlns:fx="http://ns.adobe.com/mxml/2009" 
                 xmlns:s="library://ns.adobe.com/flex/spark" 
                 xmlns:mx="library://ns.adobe.com/flex/mx"
                 width="100%">
           
           <s:layout>
                <s:VerticalLayout />
           </s:layout>
           
           <fx:Declarations>
                <!-- Place non-visual elements (e.g., services, value objects) here -->
           </fx:Declarations>
                
                <mx:Spacer height="10" />
           
                <s:Panel title="Welcome" width="100%">
                     
                </s:Panel>
           
                <s:HGroup>
                     <s:Panel width="397" height="200">
                          <MX:LinkButton />
                     </s:Panel>
                     <s:Panel width="397" height="200">
                          <MX:LinkButton />
                     </s:Panel>               
                </s:HGroup>
           
                <s:HGroup>
                     <s:Panel width="397" height="200">
                          <MX:LinkButton />
                     </s:Panel>
                     <s:Panel width="397" height="200">
                          <MX:LinkButton />
                     </s:Panel>               
                </s:HGroup>
                          
                <s:HGroup>
                     <s:Panel width="397" height="200">
                          <MX:LinkButton />
                     </s:Panel>
                     <s:Panel width="397" height="200" >
                          <MX:LinkButton />
                     </s:Panel>               
                </s:HGroup>
           
           
           
      </s:Group>
      

       

      Many Thanks

        • 1. Re: Navigation from within a custom component ???
          flairjax Level 1

          If I am understanding this correctly, you have three choices.

           

          1. Do something like ViewStack.selectedIndex(id of tab in viewstack), but not sure if selectedIndex is correct but whatever the method name is.

          2. Fire an event and set up listeners

          3. Go with a framework and use its notifications or event system

           

          If this is a production app I suggest fighting the urge to go the easy route and use a framework as before you know it you will in the middle of spaghetti code.