Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/apache-flex/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Apache flex 在子组件上禁用鼠标滚轮滚动_Apache Flex_Air - Fatal编程技术网

Apache flex 在子组件上禁用鼠标滚轮滚动

Apache flex 在子组件上禁用鼠标滚轮滚动,apache-flex,air,Apache Flex,Air,布局如下: <s:Scroller> <s:VGroup> <s:List id="list1"/> <s:List id="list2"/> <component:ThirdPartyComponent/> </s:VGroup> </s:Scroller> 因此,我的应用程序应该只显示一个向右滚动的滚

布局如下:

<s:Scroller>
    <s:VGroup>
        <s:List id="list1"/>
        <s:List id="list2"/>
        <component:ThirdPartyComponent/>
    </s:VGroup>
</s:Scroller>

因此,我的应用程序应该只显示一个向右滚动的滚动条,即scoller,list1、list2等不应该显示滚动条

在我们发现鼠标滚轮不起作用之前,它工作得很好。查看子组件(列表和第三方)捕获的
mouseweel
事件

通过网络搜索找到解决方案,有解决子
mouseweel
事件的
stopImmediatePropagation()
,但似乎不是一个好的解决方案。除了第三方公司的部分外,doing scroll是一个私人成员,因此无法收听第三方公司的
鼠标滚轮

有什么想法吗

结案
到目前为止,通过侦听
mouseWheel
事件并在那里禁用root
VGroup mouseChildren
,然后在root
VGroup
上单击处理程序,我启用
mouseChildren
但如果有更多elegan解决方案,请发表评论。

您可以通过递归访问第三方组件子级


并为您需要的儿童添加鼠标滚轮块处理程序

也许这些选项可以帮助您

选项#:1

<component:ThirdPartyComponent 
           creationComplete = "afterCreation()" 
           id               = "TPComponent">
  <fx:Script>

     // You could use initialize or creationComplete to handle MouseWheel Listener
     private function afterCreation():void{
       this.addEventListener(MouseEvent.MOUSE_WHEEL, hoverHandler);
     }
     private function hoverHandler(e:MouseEvent):void{
       if(!e.isDefaultPrevented()){
         e.preventDefault();
         e.cancelBubble = true;
         e.cancel = true;
         e.returnValue = false;
       }
       return false;
     }
  </fx:Script>
</component:ThirdPartyComponent>

//您可以使用initialize或creationComplete来处理鼠标滚轮侦听器
私有函数afterCreation():void{
this.addEventListener(MouseEvent.MOUSE_WHEEL,hoverHandler);
}
私有函数hoverHandler(e:MouseEvent):void{
如果(!e.isDefaultPrevented()){
e、 预防默认值();
e、 取消气泡=真;
e、 取消=真;
e、 returnValue=false;
}
返回false;
}
但我建议您使用MouseEvent.ROLL_OVER禁用子组件中的MouseWheel,因为它覆盖了显示对象容器的任何子对象的所有区域。buble事件应返回false,这样孩子们就没有机会调度任何鼠标事件,包括鼠标滚轮

选项#:2

<component:ThirdPartyComponent 
           creationComplete = "afterCreation()" 
           id               = "TPComponent">
  <fx:Script>

     private function afterCreation():void{
       this.mouseChildren = false;
     }

  </fx:Script>
</component:ThirdPartyComponent>

私有函数afterCreation():void{
this.mouseChildren=false;
}
通过将mouseChildren设置为false,任何mouseChildren上的事件都会神奇地提供给父级。mouseChildren不等于mouseEnabled,因此它的任何给定返回都会产生不同的影响:)


您可以组合选项1和选项2,或者选择其中一个,这对您来说是最好的:)

谢谢您的帮助,但这不是帮助,子组件无法通过
getChildAt
getChildByName
访问:(非常感谢@JackBites,您的意思是继承第三方组件吗(通过创建一个新的mxml组件)?对于选项2,我无法设置
mouseChildren=false
,因为第三方组件(日历)具有应可单击的子项。您不需要将第三方组件继承到单个mxml文件,只需在第三方组件内部添加fx:Script作为VGroup的成员。对于选项2:您可以仅基于特定事件添加mouseChildren控件,例如,如果MouseEvent.MOUSE\u WHEEL,请将mouseChildren设置为false。然后将其释放,以供使用另一个鼠标事件。