双击树节点左侧时双击事件未触发/触发

时间:2013-11-28 16:54:42

标签: flex

我有以下Flex树

<mx:Tree id="Tree" left="0" right="0" top="0" bottom="0"
         alternatingItemColors="[#EEEEEE, white]" dataProvider="{lsEspecie}"
         dragEnabled="true" dragMoveEnabled="true" dropEnabled="true" labelField="item"
         labelFunction="tree_labelFunc" showRoot="false"
         doubleClickEnabled="true" doubleClick="Tree_DoubleClick(event)">
</mx:Tree>  

当我双击ICON并在任何节点的右侧时,双击事件将按预期触发。但点击节点左侧的任何部分时,双击不会被解雇

DoubleClickNotFiredOnTheLeftOfNode

有没有办法让双击事件在节点左侧发生时触发?

2 个答案:

答案 0 :(得分:0)

您可以为树创建itemrenderer,并在其中为其HGroup添加双击侦听器。 例如-              

        protected function mxtreeitemrenderer1_creationCompleteHandler(event:FlexEvent):void
        {
            mygrp.addEventListener(MouseEvent.DOUBLE_CLICK,dblclk);
        }

        private function dblclk(event:MouseEvent):void
        {
            Alert.show("doubleclicked");
        }
    ]]>
</fx:Script>
<s:states>
    <s:State name="normal" />            
    <s:State name="hovered" />
    <s:State name="selected" />
</s:states>
<s:HGroup id="mygrp" left="0" right="0" top="0" bottom="0" verticalAlign="middle">
    <s:Rect id="indentationSpacer" width="{treeListData.indent}" percentHeight="100" alpha="0">
        <s:fill>
            <s:SolidColor color="0xFFFFFF" />
        </s:fill>
    </s:Rect>
    <s:Group id="disclosureGroup">
        <s:BitmapImage source="{treeListData.disclosureIcon}" visible="{treeListData.hasChildren}" />
    </s:Group>
    <s:BitmapImage source="{treeListData.icon}" />
    <s:Label id="labelField" text="{treeListData.label}" paddingTop="2"/>
</s:HGroup>

答案 1 :(得分:0)

看起来像是mx:Tree的错误。我添加了鼠标并将鼠标移出处理程序到我的测试应用程序以跟踪正在发生的事情。在某些情况下,双击是在您指示的红色区域中工作,我看到我的鼠标在Tree的selectionLayer上。点击并移动鼠标后,它会随机停止接受双击,此时我的鼠标总是在selectionLayer中的某些SpriteAsset上,mouseEnabled = true。

我通过继承Tree并强制selectionLayer的所有子节点都有mouseEnabled = false来解决问题:

import flash.display.InteractiveObject;
import flash.events.Event;

import mx.controls.Tree;
import mx.core.mx_internal;

use namespace mx_internal;

public class FixedTree extends Tree {

   public function FixedTree() {
      super();
   }

   override protected function createChildren():void {
      super.createChildren();

      getListContentHolder().selectionLayer.addEventListener(Event.ADDED, selectionLayerChildAddedHandler);
   }

   private function selectionLayerChildAddedHandler(e:Event):void {
      // ListBase:5790 creates a SpriteAsset for the selectionLayer but does not set mouseEnabled to false

      InteractiveObject(e.target).mouseEnabled = false;
   }

}

我不是百分百确定这是否是解决此错误的正确方法,但它为我双击工作,我还没有看到副作用。

相关问题