We help IT Professionals succeed at work.
Get Started

How to get tabnavigator's selected viewstack

trudyhlittle
trudyhlittle asked
on
4,471 Views
Last Modified: 2013-11-11
I am trying to implement a event listener when the user selects a tab on a tabnavigator that will change information elsewhere in the application depending what is currently selected.  The tab navigator contains 4 VBoxes.  Each VBox contains a linkBar that selects the appropriate viewstack item on the tab.  When the user selects a tab, I need to know which viewstack item is selected in the corresponding tab's Vbox.  I can get down as far as the selected VBox, but I can't seem to figure out how to get the label of the selected viewStack within the box.  Thanks.
<?xml version="1.0" encoding="utf-8"?> 
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"  creationComplete="init()" width="100%" >

	<mx:Style source="assets/skins/skins.css"/>

	<mx:Script>
		<![CDATA[
		
			import mx.controls.Alert;
			import events.*;
			import mx.events.ItemClickEvent;

			
			private function init():void {
			      tabNavigator.addEventListener(Event.CHANGE, tabChangedHander);
            }
            
		   
		     private function tabChangedHander(event:Event):void  
		   {  
		   	 	//need to get the label of the selected tab's current viewstack item.
		  		
		  		var temp:String = tabNavigator.getChildAt(event.currentTarget.selectedIndex).name;
		  		Alert.show("Changed: " +temp, "Changed "+ temp);
		   }
			
			private function handleTabLinkBarClickEvent(event:ItemClickEvent):void
			{
				var eNoBubble:ViewChangeEvent = new ViewChangeEvent(ViewChangeEvent.VIEWCHANGE,ViewChangeEvent.MAINTENANCE, false, event.label);
				handleViewChangeEvent(eNoBubble);
			}
			
			public function handleViewChangeEvent(event:ViewChangeEvent):void {  
				var subView:String = event.subView;
				if (subView == 'Log') {
					tabNavigator.selectedIndex = 2;
					transactionsViewStack.selectedChild = viewTranLog;
					
				} else if (subView == 'Queue') {
					tabNavigator.selectedIndex = 2;
					transactionsViewStack.selectedChild = viewQueue;
					
				}
				else if (subView == 'Errors') {
					tabNavigator.selectedIndex = 2;
					transactionsViewStack.selectedChild = viewErrors;
					
				}
				else if (subView == 'Mappings') {
					tabNavigator.selectedIndex = 0;
				} 
				else if (subView =='Connections') {
					tabNavigator.selectedIndex = 0;
					maintenanceViewStack.selectedIndex = 2;
				} 
				else if (subView =='Upload') {
					tabNavigator.selectedIndex = 1;
					processingViewStack.selectedChild = upload;
					
				} 
				else if (subView =='Download') {
					tabNavigator.selectedIndex = 1;
					processingViewStack.selectedChild = download;
					
				} 
				else if (subView =='Simulation') {
					tabNavigator.selectedIndex = 1;
					processingViewStack.selectedChild = simulation;
					
				}
			}

		]]>
	</mx:Script>

<mx:Canvas  width="100%" height="100%"  >
		<mx:TabNavigator x="248" y="65" width="78%" height="90%" 
			paddingTop="0" horizontalGap="0" tabHeight="30" id="tabNavigator" creationPolicy="all">
			<mx:VBox label="Maintenance" backgroundColor="#2D5986" backgroundAlpha="1" 
				borderStyle="solid" borderThickness="0" id="maintVbox">
					<mx:LinkBar id="maintBar"
					            dataProvider="{maintenanceViewStack}"
					            iconField="ico" 
					            linkButtonStyleName="subMenuLinkBarStyle"
					            maxHeight="28" itemClick="handleTabLinkBarClickEvent(event)"/>
					<mx:ViewStack id="maintenanceViewStack" width="100%" height="100%"  >
						<mx:Canvas id="viewMappings" label="Mappings" icon="@Embed('assets/images/MappingsSmall.png')"/>
						<mx:Canvas id="viewXref" label="X-Reference" icon="@Embed('assets/images/XreferenceSmall.png')"/>
						<mx:Canvas id="viewConn" label="Connections" icon="@Embed('assets/images/ConnectionsSmall.png')"/>
						<mx:Canvas id="viewSecurity" label="Security" icon="@Embed('assets/images/SecuritySmall.png')"/>
					</mx:ViewStack>
					
			
			</mx:VBox>
			<mx:VBox label="Processing" backgroundColor="#2D5986" backgroundAlpha="1"
				 borderStyle="solid" borderThickness="0" id="procVBox">
				<mx:LinkBar id="processBar"
					            dataProvider="{processingViewStack}"
					            iconField="ico" 
					            linkButtonStyleName="subMenuLinkBarStyle"
					            maxHeight="28" itemClick="handleTabLinkBarClickEvent(event)" />
						<mx:ViewStack id="processingViewStack" width="100%" height="100%">
							<mx:Canvas id="simulation" label="Simulation" icon="@Embed('assets/images/SimulationSmall.png')" />
							<mx:Canvas id="upload" label="Upload" icon="@Embed('assets/images/UploadSmall.png')" />
							<mx:Canvas id="download" label="Download" icon="@Embed('assets/images/DownloadSmall.png')" />
						</mx:ViewStack>
			</mx:VBox>
			<mx:VBox label="Transactions" backgroundColor="#2D5986" backgroundAlpha="1" 
				borderStyle="solid" borderThickness="0" verticalScrollPolicy="off" id="tranVbox"
				horizontalScrollPolicy="off">
				<mx:LinkBar id="transBar"
					            dataProvider="{transactionsViewStack}"
					            iconField="ico" 
					            linkButtonStyleName="subMenuLinkBarStyle"
					            maxHeight="28" itemClick="handleTabLinkBarClickEvent(event)"   />
					<mx:ViewStack id="transactionsViewStack" width="100%" height="100%"  >
						<mx:Canvas id="viewQueue" label="Queue" icon="@Embed('assets/images/QueueSmall.png')" />
						<mx:Canvas id="viewTranLog" label="Log" icon="@Embed('assets/images/LogSmall.png')" />
						<mx:Canvas id="viewErrors" label="Errors" icon="@Embed('assets/images/ErrorsSmall.png')" />
					</mx:ViewStack>
					
			</mx:VBox>
			<mx:VBox label="Reports" backgroundColor="#2D5986" backgroundAlpha="1" 
				borderStyle="solid" borderThickness="0" id="repVbox">
				<mx:LinkBar id="reportsBar"
					            dataProvider="{reportViewStack}"
					            iconField="ico" 
					            linkButtonStyleName="subMenuLinkBarStyle"
					            maxHeight="28" itemClick="handleTabLinkBarClickEvent(event)"/>
					<mx:ViewStack id="reportViewStack" width="100%" height="100%"  >
						<mx:Canvas id="report1" label="Report 1" icon="@Embed('assets/images/QueueSmall.png')" />
						<mx:Canvas id="report2" label="Report 2" icon="@Embed('assets/images/LogSmall.png')" />
						<mx:Canvas id="report3" label="Report 3" icon="@Embed('assets/images/ErrorsSmall.png')" />
					</mx:ViewStack>
			</mx:VBox>
		</mx:TabNavigator>
</mx:Canvas>
</mx:Application>

Open in new window

Comment
Watch Question
This problem has been solved!
Unlock 1 Answer and 3 Comments.
See Answer
Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

  • Troubleshooting
  • Research
  • Professional Opinions
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE