5 Replies Latest reply on Aug 17, 2009 12:24 PM by DCAKen

    Removing a Tab from a TabNavigator if a html file doesn't exist

    DCAKen Level 1

      I have created a component that contains a TabNavigator. This component will be opened in a TitleWindow when a user clicks on an item in a list (a list of survey points). There are two possible tabs in the TabNavigator: the first tab contains a Text control and the second contains a VideoDisplay control (playing a flv that exists on a server). The Text tab will always show, but the point may not have a flv file associated with it. I don't want the second tab to show if the flv file doesn't exist on the server. Here is the bulk of the code (leaving off some of the variable and functions):

       

       

      Currently, the component opens up with the Video tab visible for any of the points. But when I click on the Video tab itself, if the flv file doesn't exist, the tab will vanish. How do I code this so the tab won't show up when the component opens? The finishInitialize code doesn't remove the tab like I thought it would.

        • 1. Re: Removing a Tab from a TabNavigator if a html file doesn't exist
          kloysen

          Your code didnt appear so I am just guessing here but here is my answer.  If it isnt working after the initialize event that is probably because the dataprovider isnt there yet so when it gets set later in the code execution it redisplays everything.  What I have done in the past is overridden the set dataprovider method which will execute everytime you change your binded data.  You could also probably set an changeData event up on whatever component the xml is going into to call your script to remove the tab there.  To me it just seems like a timing issue.

          • 2. Re: Removing a Tab from a TabNavigator if a html file doesn't exist
            DCAKen Level 1

            Since the code didn't make it into my original post, here it is again:

             

            <wind:FloatingWindow 
              xmlns:wind="gov.noaa.nos.windows.*"
              xmlns:mx="http://www.adobe.com/2006/mxml"
              initialize="initWindow();" creationComplete="finishInitialize();"
              showCloseButton="false" width="320" height="320"
              >

              <mx:Script>
                <![CDATA[

                  private function initWindow():void
                  {
                    this.title="Site ID: " + TitleText;
                    videoSource = "http://server/GV_StJ/" + TitleText +".flv";
                  }
                 
                  private function finishInitialize():void
                  {
                    var request:URLRequest = new URLRequest("http://beta.w1.ccma.woc.noaa.gov/Flash/" + TitleText +".flv");
                    try
                    {
                      navigateToURL(request);    
                    }
                    catch (e:Error)
                    {
                      tabNav.getTabAt(tabNav.getChildIndex(tab2)).visible = false;
                      tabNav.getTabAt(tabNav.getChildIndex(tab2)).enabled = false;
                      tabNav.getTabAt(tabNav.getChildIndex(tab2)).includeInLayout = false;                        
                    }
                  }

                  private function videoDisplay_stateChange(evt:VideoEvent):void
                  {
                    switch (evt.state)
                    {
                      case VideoEvent.CONNECTION_ERROR:
                      evt.currentTarget.visible = false;
                      contBar.visible = false;
                      tabNav.getTabAt(tabNav.getChildIndex(tab2)).visible = false;
                      tabNav.getTabAt(tabNav.getChildIndex(tab2)).enabled = false;
                      tabNav.getTabAt(tabNav.getChildIndex(tab2)).includeInLayout = false;
                      break;
                    default:
                      evt.currentTarget.visible = true;
                      contBar.visible = true;
                      break;
                    }
                  }
                ]]>
              </mx:Script>

              <mx:VBox id="vBox" width="100%" height="100%">
                <mx:TabNavigator id="tabNav" width="100%" height="100%">
                  <mx:VBox label="Attributes">
                    <mx:Text width="100%" paddingLeft="10" paddingTop="10" text="{attributeText}"/>
                  </mx:VBox>
                          
                  <mx:VBox id="tab2" label="Video" horizontalAlign="center" paddingTop="5" >
                    <mx:VideoDisplay id="videoDisplay"
                          source="{videoSource}"
                          visible="false" autoPlay="false" playheadUpdateInterval="50"
                          width="90%" height="80%" maintainAspectRatio="true"
                          playheadUpdate="videoDisplay_playheadUpdate();"
                          ready="videoDisplay_ready();" stateChange="videoDisplay_stateChange(event);" rewind="video_Display_rewind();"/>
                  </mx:VBox>
                          
                </mx:TabNavigator>
              </mx:VBox>    
            </wind:FloatingWindow>
            • 3. Re: Removing a Tab from a TabNavigator if a html file doesn't exist
              DCAKen Level 1

              What I ended up doing is putting a hidden VideoDisplay on the first tab. This ran the stateChange event when the component was created and removed the second tab if the video didn't exist.

               

                  <mx:VBox id="vBox" width="100%" height="100%">
                      <mx:TabNavigator id="tabNav" width="100%" height="100%">
                          <mx:VBox label="Attributes">
                              <mx:Text width="100%" paddingLeft="10" paddingTop="10" htmlText ="{attributeText}"/>
                              <mx:VideoDisplay width="1" height="1" visible="false"
                                  source="{videoSource}" stateChange="videoDisplay_stateChange(event);" />
                          </mx:VBox>
                         
                          <mx:VBox id="tab2" label="Video" horizontalAlign="center" paddingTop="5" >

              • 4. Re: Removing a Tab from a TabNavigator if a html file doesn't exist
                MoonlightWare

                Try setting the creationPolicy to all

                • 5. Re: Removing a Tab from a TabNavigator if a html file doesn't exist
                  DCAKen Level 1

                  Thanks. That did the trick

                   

                  **Update**

                  I found that the creation time for the pop ups that didn't contain the video was significantly slower using creationPolicy = "all", so I went back to using a hidden VideoDisplay component on the first tab