Solved

How to initialize a tabnavigator's tabs programatically.

Posted on 2010-08-13
6
824 Views
Last Modified: 2013-11-11
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

0
Comment
Question by:trudyhlittle
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 20

Expert Comment

by:ChristoferDutz
ID: 33430194
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
 
LVL 20

Expert Comment

by:ChristoferDutz
ID: 33430242
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
 

Author Comment

by:trudyhlittle
ID: 33431796
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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 20

Accepted Solution

by:
ChristoferDutz earned 500 total points
ID: 33437583
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
 

Author Comment

by:trudyhlittle
ID: 33684305
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
 

Author Closing Comment

by:trudyhlittle
ID: 33684313
Solution was helpful but did not entirely solve the problem.
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Sometimes you know that one object has a specific child in it, but you can't find the child. This happened to me when I was trying to code some actionScript to make a toolbar work with its embedded buttons.  My partner had created the toolbar usi…
I have been doing hardcore actionscripting for some time; and needless to say I have faced a lot of problems in just understanding others' code rather than understanding what the code executes. A programmer's life can become hell when there are a lo…
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…
The goal of the tutorial is to teach the user how to set there setting in Adobe Flash Media Live Encoder and YouTube for optimal video and audio quality.

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question