以编程方式在flex ViewNavigators之间切换

时间:2014-05-21 03:09:18

标签: actionscript-3 flex view air tabnavigator

我有一个Flex TabbedViewNavigatorApplication

使用两个自定义导航器:

<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>

现在我想以编程方式,基于我的应用程序内的一些事件来切换导航器。

我发现StackOverflow上唯一的问题就是这个Switch between Flex Tabbed ViewNavigators

但该解决方案仅适用于您在Main.mxml中工作的情况, 要么使用navigator.selectedIndex = 1;(或在我的情况下为tabbedNavigator.selectedIndex = 1;)要么使用TabbedViewNavigator(navigator.parentNavigator).selectedIndex = 1;

但我不知道如何访问我的应用内的导航器,而不是Main.mxml

1 个答案:

答案 0 :(得分:0)

你必须使用一个Event,创建一个从这样的事件扩展的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;
    }

然后将事件侦听器添加到要更改选项卡的组件中。

COMPONENENT.addEventListener(NavigationEvent.GO_TO_DESTINATION, handleResult);

然后在handleResult方法中切换视图。

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