在Flex Tree中自定义拖放

时间:2013-05-28 15:17:31

标签: actionscript-3 flex

我必须从Flex Tree自定义拖动。为此,我重写了受保护的函数mouseDownHandler

override protected function mouseDownHandler(event:MouseEvent):void
{
    if ( event.target is ScrollThumb || event.target is Button )
    {
        return;
    }

    super.mouseDownHandler(event);

    var tree:Tree = Tree(event.currentTarget);

    if (tree.selectedItem && tree.indexToItemRenderer(tree.selectedIndex) && tree.selectedItem is Image)
    {
        var image:Image = Image(tree.selectedItem);
        var source:DragSource = new DragSource();
        var dragView:Image = new Image();
        dragView.source = drawGhost(image);
        var dragInitiator:UIComponent = UIComponent(tree.indexToItemRenderer(tree.selectedIndex));
        var ghostOffset:Point = dragInitiator.globalToLocal(new Point(event.stageX, event.stageY));
        DragManager.doDrag(dragInitiator, source, event, dragView, ghostOffset.x, ghostOffset.y, 1);
    }
}

private function drawGhost(image:Image):Bitmap
{
    var ghostWidth:int = image.source.width;
    var ghostHeight:int = image.source.height;

    var sprite:Sprite = new Sprite();
    sprite.graphics.beginFill(0xFF0000, 0.5);
    sprite.graphics.drawRect(0, 0, ghostWidth, ghostHeight);
    sprite.graphics.endFill();

    var bitmapData:BitmapData = new BitmapData(sprite.width, sprite.height, false);
    bitmapData.draw(sprite);
    var bitmap:Bitmap = new Bitmap(bitmapData);

    return bitmap;
}

但我遇到了两个问题:

  1. 如果我的幽灵的宽度或高度超过300像素,则会出现渐变透明度。我不需要它。我怎么能禁用这个功能?
  2. 第二个问题不太重要:拖动树元素会导致垂直滚动。有任何想法如何禁用它?
  3. 渐变透明度示例: Gradient transparency example

1 个答案:

答案 0 :(得分:0)

您可以通过将verticalScrollPolicy设置为“关闭”来禁用垂直滚动。

关于“Gradient”-thing:尝试更改光标以在DragManager中拖动到某个自定义类。