简体   繁体   中英

Programmatically switch between flex ViewNavigators

I have a Flex TabbedViewNavigatorApplication

With two custom navigators:

<s:navigators>
    <homepagenavigator:HomePageNavigatorView label="Home" id="homePageNavigator" width="100%" height="100%" />
    <categorylistpagenavigator:CategoryListPageNavigatorView label="List of Categories" id="categoryListPageNavigatorView" width="100%" height="100%" />
</s:navigators>

Now I want to programmatically, based on some events inside my app to switch between navigators.

The only question on StackOverflow I found is this Switch between Flex Tabbed ViewNavigators

but the solution is only applicable if you are working inside your Main.mxml, which is either to use navigator.selectedIndex = 1; (or in my case tabbedNavigator.selectedIndex = 1; ) or to use TabbedViewNavigator(navigator.parentNavigator).selectedIndex = 1;

but I have no idea how to access navigator inside my app, not in Main.mxml

you will have to use an Event, create a NavigationEvent that extends from event like this:

  public class NavigationEvent extends Event
{
    public static const GO_TO_DESTINATION:String = "goToDestination";

    private var _destIndex:Number;
    private var _param:Object;

    public function NavigationEvent(type:String, destIndex:Number)
    {
        super(type, true);
        this._destIndex = destIndex;
    }

And then add the event listener to the component from where you want to change the tab.

COMPONENENT.addEventListener(NavigationEvent.GO_TO_DESTINATION, handleResult);

And then in the handleResult method switch the view.

 private function goto(event:NavigationEvent):void{
            vs.selectedIndex = event.destIndex;
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM