Avatar of John Gillen
John Gillen
Flag for United States of America asked on

Flex tabNavigator

I have a project which consists of a basic tab Navigator component with several tabs. I set a default tab and then build a release run and all is well.  Lets say this file is called test.html.  I have been told that they would like to have links elsewhere on the site that will call this test.html, however they would want a different tab then the default to be open at the start. So is there a way  that this file can be called from a link being passed a parameter that will set the tab that is open?
I have seen nothing as of yet in my flex journeys - still a relative newbie with all of this.
Apache Flex

Avatar of undefined
Last Comment
John Gillen

8/22/2022 - Mon
ASKER CERTIFIED SOLUTION
Gary Benade

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
SOLUTION
lexxwern

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
John Gillen

ASKER
Hobbit72's option appears to be exactly what I want to achieve, but there has to be more to it; how do you prepare the mxml file to receive a parameter? Also if I do need to enable deep linking then I guess I will have to bite the bullet on that one although it appears to be more involved than I would want to go for this somewhat simple task at least in the html world.

Thanks
lexxwern

Hmm.. Flex 3 already has this feature built in.. It is called deeplinking which by default is "on" in a Flex application.. I don't think you need to write any custom code for this.. :-/
John Gillen

ASKER
Well this is potentially good news, but I can't believe it's just as easy as hobbit72 put it just pass a parameter to the html file - you don't know of a small example file that's out here - I'm a visual learner and learn best by seeing a working example. Just a simple tab navigator  with for simplicity sake two tabs setup so when file first opens:
:
test.html?tabparam=1 opens tab 1
test.hrml?tabparam=2 opens tab 2

Thanks
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
Gary Benade

It is as easy as that. Add this to your applications startup code

switch( Application.application.parameters.tabparam)
{
 case 1:
    tabControl.selectedIndex = 0;
  break;
 case 2:
    tabControl.selectedIndex = 1;
  break;
}
John Gillen

ASKER
I've attached a very simple code sample - the statements cannot see my "tabNav" - obviously I am doing something wrong.
<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"> 
 
<mx:TabNavigator id="tabNav" creationComplete="init();" width="942" height="167">
<mx:Canvas id="t0" label="Decking Home"/>
<mx:Canvas id="t1" label="Availbility"/>
<mx:Canvas id="t2" label="Related Items"/>
<mx:Canvas id="t3" label="Decking Gallery"/>
<mx:Canvas id="t4" label="Latitudes"/>
<mx:Canvas id="t5" label="TimberTech"/>
<mx:Canvas id="t6" label="Trex"/>
<mx:Canvas id="t7" label="Azek"/>
        
</mx:TabNavigator>
</mx:Application>

Open in new window

Gary Benade

It probably hasn't been created yet.. are you accessing tabNav from the init() function or from somewhere else?

What does that code look like?
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
John Gillen

ASKER
I've attached the entire code that I was attempting to modify, as you can see I was playing with moving the tabs around.  I was not entirely sure where your switch statement would go in this mess.

I can't thank you enough for the help with this!!!!

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml">
<mx:Script>
 
<![CDATA[
import mx.controls.tabBarClasses.Tab;
private function init():void {
var tab:Tab;
var tabWidth:int = 0;
tab = tabNav.getTabAt(0) as Tab;
tabWidth += tab.width;
//no need to move tab 0 as that goes on the left
tab = tabNav.getTabAt(1) as Tab;
tabWidth += tab.width;
tab = tabNav.getTabAt (2) as Tab;
tabWidth += tab.width;
tab = tabNav.getTabAt (3) as Tab;
tabWidth += tab.width;
tab = tabNav.getTabAt(4) as Tab;
tabWidth += tab.width;
tab = tabNav.getTabAt(5) as Tab;
tabWidth += tab.width;
tab = tabNav.getTabAt(6) as Tab;
tabWidth += tab.width;
tab.move(800, tab.y);
tab = tabNav.getTabAt(7) as Tab;
tab.move(tabNav.width-tab.width,tab.y); 
}
]]>
</mx:Script>
<mx:TabNavigator id="tabNav" creationComplete="init();" width="942" height="167">
<mx:Canvas id="t0" label="Decking Home"/>
<mx:Canvas id="t1" label="Availbility"/>
<mx:Canvas id="t2" label="Related Items"/>
<mx:Canvas id="t3" label="Decking Gallery"/>
<mx:Canvas id="t4" label="Latitudes"/>
<mx:Canvas id="t5" label="TimberTech"/>
<mx:Canvas id="t6" label="Trex"/>
<mx:Canvas id="t7" label="Azek"/>
        
</mx:TabNavigator>
</mx:Application>

Open in new window