`
icediv
  • 浏览: 77040 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Flex的TabNavigator中tab触发的事件

    博客分类:
  • Flex
阅读更多

最近用到TabNavigator,想在那个tabBar上点选的时候触发一个自己的回调方法,可是想象中触发的事件和实际真正应该用到的那个是不一样的!最有意思的是,并不是我一个人遇到这样的困惑,一个老外也和我一个感觉,不知道是是该高兴,还是该怎么的。

 

其实很容易的,就是说点击TabNavigator上的选项卡时触发的是IndexChangedEvent.CHANGE,而不是那个tabIndexChange。

 

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="InitApp()">
<mx:Script>
    <![CDATA[
        import mx.events.IndexChangedEvent;
        private function InitApp():void
        {
            tabnavigator1.addEventListener(IndexChangedEvent.CHANGE,indexChangeHandler);
        }
        function indexChangeHandler(event:IndexChangedEvent):void
        {
            this.currentState='HideReminderEntry';
            mybutton.label=tabnavigator1.getTabAt(tabnavigator1.selectedIndex ).label
//            if (event.triggerEvent is MouseEvent)
//                recordAutomatableEvent(event, false);
//            else
//                recordAutomatableEvent(event.triggerEvent, false);
        }
    ]]>
</mx:Script>

 
 

 

老外原文:

 

--------------------------------------------------------

Getting Around Bug in Adobe Flex: TabControl Inline Event Handling for TabIndexChange Doesn't Work

I ran into this because I wanted to do something funky.  I wanted my Flex app window to change PageStates (and size) whenever the TabIndex changed.  Whether doing this kind of thing is wise in a user interface is yet to be seen -- I did it and it even strikes ME as a bit off the wall -- but it did solve the immediate issue.  The immediate issue was that some of my tabs required a lot of space and some did not.  This left a lot of ugly whitespace.

So, I figured, Flex (Actually Flash under the covers) must have an event handler for changing tabs.  And I was rewarded very quickly:  There is a "TabIndexChange" inline event handler.  For the uninitiated, such a thing looks something like this:

<mx:TabNavigator id="tabnavigator1" tabIndexChange="myHandlerFunction()">

With most other events, this works just fine:  When the event fires, the handler is called.  But it simply doesn't work in this case.  The handler function is never called.

There's a couple of ways to handle this.  One way is to use a TabBar control rather than a TabControl.  The TabBar basically gives you the look and feel of a tabset but more control over what is tabbed.  And the tabIndexChange even calls the handler as one might expect.

I didn't want to do it that way, however.  For one thing, I'm stubborn.  For another, I already had all my controls arranged on the TabNavigator and I didn't want to rip it half to pieces to get functionality that I should already be getting.

Fortunately, there's a solution:  Explicitly declare an event listener.  That looks something like this:

<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="InitApp()">
<mx:Script>
    <![CDATA[
        import mx.events.IndexChangedEvent;
        private function InitApp():void
        {
            tabnavigator1.addEventListener(IndexChangedEvent.CHANGE,indexChangeHandler);
        }
        function indexChangeHandler(event:IndexChangedEvent):void
        {
            this.currentState='HideReminderEntry';
            mybutton.label=tabnavigator1.getTabAt(tabnavigator1.selectedIndex ).label
//            if (event.triggerEvent is MouseEvent)
//                recordAutomatableEvent(event, false);
//            else
//                recordAutomatableEvent(event.triggerEvent, false);
        }
    ]]>
</mx:Script>

 

Important things to note:

  1. The handler must be declared in code, and it should run when the page load is complete.  So, in the mx:Application tag, there is the inline event, creationComplete="InitApp()".
  2. Any function name can be used here, but InitApp() is by convention.
  3. You'll need the "import mx.events.IndexChangedEvent," or you'll get a class-not-defined error.
  4. Wire up the event listener with: 
  5. tabnavigator1.addEventListener(IndexChangedEvent.CHANGE,indexChangeHandler);
  6. Finally, as a very small bonus (I'm learning all this too), there's the commented code talking about "if (event.triggerEvent is MouseEvent)".  So it turns out you can distinguish between whether the event occurred as the result of a keyboard event (likely Tab), or as a mouseevent.  I don't see a use for it here, but it's applicable to ALL events, including, say, Focus() events, where it might have some use.  Flex -- actually, ActionScript, its programming language -- is really nifty.

FYI, as a parting note, as far as I can tell SilverLight is intended to be a direct competitor to Flex.  Flex has somewhere around a seven-year head start.  Don't count Microsoft out, of course -- how many people really use Netscape anymore? -- but on the other hand, you never hear about J++ anymore either.  Bottom line:  Those who are considering SilverLight should also consider Flex.  It's incredibly robust, easy to use, has a full-featured IDE that includes powerful debugging capabilities, and there's lots of great resources on it to help people learn.  I've been using the videos at Lynda.com.  In fact, watching one of them got me over the hump on this issue.  So, I recommend Lynda.com wholeheartedly.

 

来自:http://theruntime.com/blogs/be-sharp/archive/2008/03/11/Getting-Around-Bug-in-Adobe-Flex-TabControl-Inline-Event-Handling-for-TabIndexChange-Doesnt-Work.aspx

2
0
分享到:
评论

相关推荐

    flex TabNavigator tab倒置

    在Flex开发中,TabNavigator组件是常用于创建带有选项卡的用户界面的工具。它允许用户在多个视图之间切换,每个视图对应一个选项卡。"flex TabNavigator tab倒置"这个标题可能指的是开发者想要实现一个特殊的布局,...

    Flex tabNavigator 的初级应用

    NULL 博文链接:https://zhangyinyou.iteye.com/blog/671128

    flex3 tabnavigator一个很好的例子

    同时,TabNavigator还支持`change`事件,当用户切换选项卡时触发。 4. **皮肤和样式**:Flex3允许开发者自定义组件的外观,包括TabNavigator的选项卡样式。通过改变`skinClass`属性或使用CSS,可以改变选项卡的颜色...

    Flex中实现多行tab的源代码

    在Flex开发中,创建用户界面时,我们常常会遇到需要展示多行Tab导航的情况。默认情况下,Flex的TabNavigator组件的TabBar控件只会在一行内显示Tab项,但通过自定义布局和样式,我们可以轻松实现多行Tab的展示。本...

    Flex4.6 带图标的TabNavigator的使用

    此外,`TabNavigator`还支持各种事件处理,比如`tabChange`事件,当用户切换选项卡时会触发。这使得我们可以根据当前选中的选项卡执行特定的操作或更新内容。 在`TabNavigatorIconDemo`这个示例中,你可能会找到一...

    flex checkboxtree 和可增加面板,可关闭的tab页

    3. **事件处理**:当用户点击关闭按钮时,触发一个事件,然后在父容器(即`TabNavigator`)中处理该事件,移除对应的`Tab`。 4. **添加新Tab**:提供一个接口让用户添加新的`Tab`,这可能包括输入新Tab的标题或其他...

    设置TabNavigator组件的标签头的自定义皮肤

    在React Native或React.js等JavaScript框架中,TabNavigator是常用的组件库之一,如React Navigation。本文将详细探讨如何为TabNavigator组件的标签头设置自定义皮肤,以实现个性化的设计需求。 首先,我们需要了解...

    Flex3 TabNavigator

    在Flex3中,TabNavigator是一种容器控件,用于展示多个视图,并且这些视图可以通过标签页进行切换。TabNavigator的每个标签页通常关联一个ViewStack或其他容器,用于存放不同的内容。然而,标准的TabNavigator并不...

    Flex3 竖排TabNavigator

    在Flex3中,TabNavigator是一个容器组件,用于展示多个子组件,并通过标签页的形式进行切换。默认情况下,TabNavigator的标签页是水平排列的,但在这个特定的实例中,我们将讨论如何将TabNavigator的标签页设置为...

    flex 遮盖式 TabNavigator

    在Flex中,TabNavigator是一种容器组件,用于创建带有可切换选项卡的用户界面。它允许用户在不同的内容区域之间轻松导航,每个区域对应一个单独的选项卡。"遮盖式 TabNavigator"可能指的是在设计时或运行时...

    flex模板,多TAB

    在本项目中,"flex模板,多TAB"是指一个实现了多个标签(Tab)页面切换功能的Flex应用。这样的设计通常用于创建具有多个视图或工作区的应用,让用户能够方便地在不同功能之间切换。 1. **MainView.mxml**:这是应用...

    Flex中TabNavigator设置Tabs样式思路及

    在Flex框架中,TabNavigator组件是用来创建标签导航界面的一种方式,它能够展示一组标签页,每个标签页关联一个视图。在Flex应用中,为了提升用户体验,通常需要对TabNavigator的Tabs进行样式定制,使得它们更符合...

    flex 和 flexlib类库 实现 菜单和 TabNavigator

    NULL 博文链接:https://toeo.iteye.com/blog/644341

    flex TabNavigatorTab 选项卡标题标签皮肤设置

    这是一个封装好的flex项目,可以直接运行,TestTabNavigator.mxml是运行主页。里面定义了TabNavigator控件选中与被选中的皮肤类,皮肤类可以自己进行更改,也可以设置颜色渐变等等。希望对大家有帮助。

    flex中文帮助.rar

    8. **事件处理**:Flex应用中的事件处理是通过事件监听器实现的,允许程序对用户的交互做出响应,如点击按钮、关闭窗口等。 9. **图形和动画**:Flex提供了强大的图形绘制和动画功能,可以创建复杂的矢量图形和动态...

    Flex4.0API中文手册完整版

    Flex 4.0 API中文手册是为Adobe Flex 4.0框架提供的一份全面的开发者参考资料,它包含了大量的类库、方法、属性和事件的详细解释,帮助开发者深入理解和使用Flex进行富互联网应用(RIA)的开发。Flex是基于...

    Flex 选项卡的实现

    在Flex编程中,选项卡(Tab)是一种常见的用户界面组件,用于组织和切换多个视图或内容区域。本文将深入探讨如何在Flex中实现选项卡功能,并通过代码示例和实际效果展示其工作原理。 首先,我们需要理解Flex的基础...

    React-Native 实现点击Tab标签切换Tab页面

    在React-Native开发中,创建一个用户界面时,Tab导航是一种常见的设计模式,它允许用户在不同的视图之间轻松切换。本教程将详细介绍如何使用React-Native中的TabBar组件来实现点击Tab标签切换Tab页面的功能。 首先...

    Flex页面跳转.txt

    3. **设置事件监听器**:监听TabNavigator的选择变化事件。 ```as3 private function tabNav_creationCompleteHandler(event:Event):void { tabNav.addEventListener(mx.events.FlexEvent.TAB_CHANGED, tabNav_...

    TabNavigator_ScrollableMenu

    在Flex开发中,TabNavigator组件是常用于创建带有可切换选项卡的应用界面。然而,随着应用复杂度的提升,用户对于更加灵活和易用的选项卡导航的需求也在不断增长。"TabNavigator_ScrollableMenu"便是为满足这一需求...

Global site tag (gtag.js) - Google Analytics