`
hehailin1986_163.com
  • 浏览: 153958 次
  • 性别: Icon_minigender_1
  • 来自: 成都
社区版块
存档分类
最新评论

[Forward]AS3 Double Click and mouseChildren

阅读更多

From http://www.charglerode.com/blog/?p=54

 

As an interface and game developer, I find myself struggling with Flash as a development platform because of it’s lack of support for common inputs. Flash has grown over the last decade as a serious casual gaming platform, but has only recently begun to support such inputs as mouse wheel and double click. Don’t even get me started on right button click and Adobe’s obvious decision to leave it as it is. I digress.

Anyhow, the real reason for this post was to expose a little caveat with the double click mouse event in AS3. I fought with this and dug through the documentation for many hours until I finally found the solution. Setting up the double click mouse event is the same as any other mouse event:

1
myButton.addEventListener( MouseEvent.DOUBLE_CLICK, myHandler );

I excluded the handler function because that part is irrelevant to the solution. Now, if you were to try this by itself, you would notice that this doesn’t actually work. Ok, so if you have a simple clip with no children, the next snippet will fix the problem:

1
2
myButton.doubleClickEnabled = true;
myButton.addEventListener( MouseEvent.DOUBLE_CLICK, myHandler );

What the heck is that? Well, apparently in order for a double click to fire, you have to enable it. Seems odd, I know, but I’m guessing it is a feature used to save a few cycles. I guess we can’t complain too much, at least we have double click now. For most cases, the last part would have fixed your issue. However, if you’re like me and your buttons are more complex with multiple children, you may still notice that this doesn’t work. This is where I struggled. The next part will finally fix the problem for all cases simple to complex:

1
2
3
myButton.mouseChildren = false;
myButton.doubleClickEnabled = true;
myButton.addEventListener( MouseEvent.DOUBLE_CLICK, myHandler );

Ok, so this is a little more obscure, but it does fix the problem. Now, let me explain what this is and why you need it. When a sprite contains children, those children will accept mouse input as well. Sometimes, the input will be registered to one of the children instead of the parent clip. So, when you attach a listener to the parent, and a child fires the event, you will never receive the event. The solution, set mouseChildren to false to tell the clip not to let any of its children accept mouse inputs. This way the parent clip will accept mouse input and fire the appropriate event.

Hopefully you found this before you spent as many hours as I did fumbling around.

 

 

分享到:
评论

相关推荐

    as3制作鼠标心型跟随效果

    在本文中,我们将深入探讨如何使用ActionScript 3(AS3)来实现一个有趣的互动效果:鼠标心形跟随。ActionScript是Adobe Flash Professional中的编程语言,用于创建动态内容,如动画和交互式应用程序。这个“鼠标...

    AS3+xml下拉菜单_下拉弹出框菜单

    在本文中,我们将深入探讨AS3.0与XML结合实现的下拉菜单和弹出框菜单的原理、设计以及实际应用。AS3.0(ActionScript 3.0)是Adobe Flash开发中的主要编程语言,它提供了强大的功能和高效的性能。XML(eXtensible ...

    flash as3.0代码优化

    在探讨“Flash AS3.0代码优化”这一主题时,我们深入分析了如何提升Flash应用程序的性能,确保其运行更加流畅、高效。以下是从给定文件的标题、描述、标签和部分内容中提炼出的关键知识点: ### 1. DisplayObject ...

    (精品word)Flash.as数字拼图游戏代码.doc

    在 Flash ActionScript 3 (AS3) 中,这个游戏的核心逻辑是通过创建和管理一系列小方块,这些方块包含了数字,并且可以进行移动以完成拼图。下面我们将详细探讨其中涉及的主要知识点: 1. **ActionScript 3 基础**:...

    flash游戏中的文本热区导航

    这个技术主要应用于AS3(ActionScript 3)环境中,因为AS3是Flash开发的主要编程语言。本文将深入探讨如何实现这种功能,以及为何不使用TextField的link方式。 1. **AS3基础与文本对象**: AS3是ActionScript的第...

    画线,对象拖动,自定义鼠标

    首先,"画线"在Flash中通常通过AS3(ActionScript 3)编程来实现。AS3是Flash平台的主要编程语言,它提供了强大的图形绘制功能。用户可以通过`Graphics`类的方法如`beginFill()`和`lineTo()`来创建线条和形状。例如...

    Flex 画线 可以给线条增加事件

    myLine.addEventListener(MouseEvent.CLICK, lineClicked); private function lineClicked(event:MouseEvent):void { trace("线条被点击"); // 在这里添加处理点击事件的代码 } ``` 3. 改变鼠标指针: ...

    flex 自定义右键菜单

    customMenuItem.mouseChildren = false; // 确保点击触发事件 customMenuItem.buttonMode = true; customMenuItem.addEventListener(MouseEvent.CLICK, onMenuItemClick); customMenu.addChild(customMenuItem);...

    Flex 开发技巧集

    6. **AS3工程设置属性**:通过 `[SWF]` 元数据标签,可以设置SWF的宽度、高度、背景颜色和帧率。 7. **Label控件实现手型图标**:通过设置`useHandCursor`, `mouseChildren`和`buttonMode`属性,可以使Label具有...

    Flash优化技巧整理

    **3、当不需要鼠标事件的时候将mouseEnabled和mouseChildren设为false** - **鼠标事件**: 关闭不需要的鼠标事件监听器可以降低CPU负载。 **4、对执行时间太长的非动画内容,优先选择计时器,而非Event.ENTER_FRAME...

    flex 窗体拖拽,可以自由拖拽,最大化,最小化等等

    这可以通过设置窗体的`mouseChildren`属性为`false`,然后在窗体上添加一个覆盖整个区域的透明薄膜,监听薄膜上的鼠标事件来实现。 在Flex开发中,理解并掌握这些基本的窗体交互技巧是至关重要的,它们能帮助我们...

    FLASH游戏渲染技术

    - **合理使用事件监听器**:关闭不必要的鼠标事件监听器,如`mouseEnabled`和`mouseChildren`,可以降低系统负担,提高游戏运行的流畅度。 #### 五、综合应用案例 根据文章提供的数据,使用`copyPixels`进行1000次...

Global site tag (gtag.js) - Google Analytics