简体   繁体   English

在Flex ViewNavigator之间以编程方式切换

[英]Programmatically switch between flex ViewNavigators

I have a Flex TabbedViewNavigatorApplication 我有一个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 我发现的关于StackOverflow的唯一问题是在Flex选项卡式ViewNavigator之间切换

but the solution is only applicable if you are working inside your Main.mxml, which is either to use navigator.selectedIndex = 1; 但是该解决方案仅适用于在Main.mxml中进行工作的情况,即使用navigator.selectedIndex = 1; ;。 (or in my case tabbedNavigator.selectedIndex = 1; ) or to use TabbedViewNavigator(navigator.parentNavigator).selectedIndex = 1; (或者在我的情况下为tabbedNavigator.selectedIndex = 1; ),或使用TabbedViewNavigator(navigator.parentNavigator).selectedIndex = 1;

but I have no idea how to access navigator inside my app, not in Main.mxml 但是我不知道如何在我的应用程序中访问导航器,而不是在Main.mxml中

you will have to use an Event, create a NavigationEvent that extends from event like this: 您将必须使用事件,创建一个从事件扩展的NavigationEvent,如下所示:

  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. 然后在handleResult方法中切换视图。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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