PDA

View Full Version : Removing a Tab from a TabNavigator if a flv file doesn't exist


DCAKen
08-07-2009, 09:31 PM
I have created a component that contains a TabNavigator. This component will be opened 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). 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):


<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)).visibl e = false;
tabNav.getTabAt(tabNav.getChildIndex(tab2)).enable d = false;
tabNav.getTabAt(tabNav.getChildIndex(tab2)).includ eInLayout = 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)).visibl e = false;
tabNav.getTabAt(tabNav.getChildIndex(tab2)).enable d = false;
tabNav.getTabAt(tabNav.getChildIndex(tab2)).includ eInLayout = 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>


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.