0

我必须从 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. 第二个问题不太重要:拖动树元素会导致垂直滚动。任何想法如何禁用它?

渐变透明度示例: 渐变透明度示例

4

1 回答 1

0

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

关于“渐变”的东西:尝试将用于在 DragManager 中拖动的光标更改为某个自定义类。

于 2013-05-29T06:33:38.657 回答