How to initialize a tabnavigator's tabs programatically.

I have a  tabnavigotor which contains vBox objects for the tabs.  Within each VBox is a LinkBar and a ViewStack.  I want to programatically select a tab and an item within the ViewStack.  My problem is that because the tab hasn't been navigated to, the viewstack object is null.  I do not want to set the creationPolicy to all.  There is a lot of data within the each of the tabs and view stacks that I do not want retrieved and created unitl required for performance reasons.  How can I get the viewStack to intantiate when I select the tab index?
<mx:TabNavigator x="248" y="65" width="78%" height="90%" 
			paddingTop="0" horizontalGap="0" tabHeight="30" id="tabNavigator"   >
			<mx:VBox label="Maintenance" backgroundColor="#2D5986" backgroundAlpha="1" 
				borderStyle="solid" borderThickness="0">
					<mx:LinkBar id="maintBar"
					            dataProvider="{maintenanceViewStack}"
					            iconField="ico" 
					            linkButtonStyleName="subMenuLinkBarStyle"
					            maxHeight="28" itemClick="handleTabLinkBarClickEvent(event)"
					             />
					<mx:ViewStack id="maintenanceViewStack" width="100%" height="100%" creationComplete="initMaintenanceLinkBar()" >
						<mmappings:ViewMappings id="viewMappings" label="Mappings" icon="@Embed('assets/images/MappingsSmall.png')"/>
						<mxref:ViewXref id="viewXref" label="X-Reference" icon="@Embed('assets/images/XreferenceSmall.png')"/>
						<mconn:ViewAdaptersCanvas id="viewConn" label="Connections" icon="@Embed('assets/images/ConnectionsSmall.png')"/>
						<msecurity:SecurityMaintenanceCanvas 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">
				<mx:LinkBar id="processBar"
					            dataProvider="{processingViewStack}"
					            iconField="ico" 
					            linkButtonStyleName="subMenuLinkBarStyle"
					            maxHeight="28" itemClick="handleTabLinkBarClickEvent(event)" />
						<mx:ViewStack id="processingViewStack" width="100%" height="100%" creationComplete="initProcessingLinkBar()" >
							<processing:SimulationCanvas id="simulation" label="Simulation" icon="@Embed('assets/images/SimulationSmall.png')" />
							<processing:UploadCanvas id="upload" label="Upload" icon="@Embed('assets/images/UploadSmall.png')"  />
							<processing:DownloadCanvas 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"
				horizontalScrollPolicy="off" id="transactionsVBoxTab">
				<mx:LinkBar id="transBar"
					            dataProvider="{transactionsViewStack}"
					            iconField="ico" 
					            linkButtonStyleName="subMenuLinkBarStyle"
					            maxHeight="28" itemClick="handleTabLinkBarClickEvent(event)" />
					<mx:ViewStack id="transactionsViewStack" width="100%" height="100%" creationComplete="initTransactionsLinkBar()"  >
						<vqueue:ViewTranQueueCanvas id="viewQueue" label="Queue" icon="@Embed('assets/images/QueueSmall.png')" />
						<vlog:ViewTranLogCanvas id="viewTranLog" label="Log" icon="@Embed('assets/images/LogSmall.png')" />
						<verr:ViewErrorsCanvas 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">
				<mx:LinkBar id="reportsBar"
					            dataProvider="{reportsViewStack}"
					            iconField="ico" 
					            linkButtonStyleName="subMenuLinkBarStyle"
					            maxHeight="28" itemClick="handleTabLinkBarClickEvent(event)"/>
					<mx:ViewStack id="reportsViewStack" width="100%" height="100%"  >
						<reports:ResponseCanvas id="responseReports" label="Responses" icon="@Embed('assets/images/ResponsesSmall.png')" />
						<reports:BillingCanvas id="billingReports" label="Billing" icon="@Embed('assets/images/dollar.png')" />
						<reports:AuditingCanvas id="auditingReports" label="Auditing" icon="@Embed('assets/images/AuditingSmall.png')" />
					</mx:ViewStack>
			</mx:VBox>
		</mx:TabNavigator>

public function handleViewChangeEvent(event:ViewChangeEvent):void {  
				var subView:String = event.subView;
				var accessType:String = sessionData.participantUser.userAccessSecurity[subView];
				var editAuthorization:Boolean = true;
			
				if(accessType == 'V') {
					editAuthorization = false;
				}
				
				if (subView == 'Log') {
					tabNavigator.selectedIndex = 2;
					transactionsViewStack.selectedChild = viewTranLog; //throws null object error
					resetContextMenu(ResetContextMenuEvent.PAGE_TRANSACTIONLOG);
				} else if (subView == 'Queue') {
					tabNavigator.selectedIndex = 2;
					transactionsViewStack.selectedChild = viewQueue; //throws null object error
					resetContextMenu(ResetContextMenuEvent.PAGE_TRANSACTIONQUEUE);
				}
				else if (subView == 'Errors') {
					tabNavigator.selectedIndex = 2;
					transactionsViewStack.selectedChild = viewErrors; //throws null object error
					resetContextMenu(ResetContextMenuEvent.PAGE_ERRORLOG);
				}
				else if (subView == 'Mappings') {
					tabNavigator.selectedIndex = 0;
					maintenanceViewStack.selectedIndex = 0;
					resetContextMenu(ResetContextMenuEvent.PAGE_NOMENU);
				} 
				else if (subView =='Connections') {
					tabNavigator.selectedIndex = 0;
					maintenanceViewStack.selectedChild = viewConn;
					viewConn.setFieldEditable(editAuthorization);
					resetContextMenu(ResetContextMenuEvent.PAGE_ADAPTERSETUP);
				} else if (subView == 'Security') {
					resetContextMenu(ResetContextMenuEvent.PAGE_SECURITY);
				}
				else if (subView =='Upload') {
					tabNavigator.selectedIndex = 1;
					processingViewStack.selectedChild = upload; //throws null object error
					resetContextMenu(ResetContextMenuEvent.PAGE_NOMENU);
				} 
				else if (subView =='Download') {
					tabNavigator.selectedIndex = 1;
					processingViewStack.selectedChild = download; //throws null object error
					resetContextMenu(ResetContextMenuEvent.PAGE_NOMENU);
				} 
				else if (subView =='Simulation') {
					tabNavigator.selectedIndex = 1;
					processingViewStack.selectedChild = simulation; //throws null object error
					resetContextMenu(ResetContextMenuEvent.PAGE_NOMENU);
				}
				else if (subView =='Responses') {
					tabNavigator.selectedIndex = 3;
					reportsViewStack.selectedChild = responseReports; //throws null object error
					resetContextMenu(ResetContextMenuEvent.PAGE_RESPONSES);
				}
				else if (subView =='Billing') {
					tabNavigator.selectedIndex = 3;
					reportsViewStack.selectedChild = billingReports; //throws null object error
					resetContextMenu(ResetContextMenuEvent.PAGE_NOMENU);
				}
				else if (subView =='Auditing') {
					tabNavigator.selectedIndex = 3;
					reportsViewStack.selectedChild = auditingReports; //throws null object error
					resetContextMenu(ResetContextMenuEvent.PAGE_NOMENU);
				}
				else if (subView == ViewChangeEvent.SUBMENUIGNORE) {
					// ignore this because it is coming from the menu bar
				} 
				else {
					resetContextMenu(ResetContextMenuEvent.PAGE_NOMENU);
				}
			}

Open in new window

trudyhlittleAsked:
Who is Participating?
 
ChristoferDutzCommented:
Well in your case you have more visual components ... the DropDownBox. I posted an example of one of my projects, in youre case simply replace the DropDownList with your LinkBar. There should not be a real difference.
0
 
ChristoferDutzCommented:
Hi,

I solved this problem by using the mxml binding. All elements shown in the ViewStack posses a "label" property and I bind the data-provider of the DropDownList to the ViewStack and the selectedItem of the ViewStack to the selectedItem of the DropDownList. In my code example, I dynamically load modules which are then added to the ViewStack and hereby are automatically added to the DropDownList.
<s:DropDownList id="environmentTypeInput" width="100%"
    change="updateEnvironmentType()"
    dataProvider="{environmentTypeStack}"/>

...

<mx:ViewStack id="environmentTypeStack" width="100%" height="100%"
    selectedIndex="{environmentTypeInput.selectedIndex}">

    <s:NavigatorContent id="unspecifiedCredentialType"
        label="{ResourceManager.getInstance().getString('environments', 'SelectEnvironmentType')}"/>
    
    ... dynamically loaded components ...
    
</mx:ViewStack>

Open in new window

0
 
ChristoferDutzCommented:
All you have to do now, is to react on the "creation-complete" Event and to select the desired value of the DropDownList ... in my case I iterate through the elements of the data-provider and set "environmentTypeInput.selectedItem = curViewStackElement;" ... should also work for you.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

 
trudyhlittleAuthor Commented:
I'm sorry, but I'm a little confused as to what I am suppose to bind to.  In my case, I only have one visual component, the tab navigator.  What two objects should I be binding together?  I tried binding the view stack to the linkbar and setting the selected index on the linkbar instead of the viewstack, but since the linkbar is on the tab, it is also not instantiated yet.
0
 
trudyhlittleAuthor Commented:
Sorry for the delay on this.  I got sidetracked to a differnt project.
I bound my viewstack to the linkbar and that got me part of the way there.  I was still getting errors when I was trying to set the linkbar item programatically (via a shortcut button) when the tab and therefore the viewstack hadn't been created yet.

To resolve this, I now store the index I want to change to on my event that selected the appropriate tab.  Once the viewstack has been created (ie the creationComplete event fires), I set the selected index of the LinkBar to the stored index.

Thanks.  And again, sorry for the delay on this.
0
 
trudyhlittleAuthor Commented:
Solution was helpful but did not entirely solve the problem.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.