1

Flex にはリスト コントロール用のドラッグ アンド ドロップが組み込まれており、これをオーバーライドできます。しかし、彼らはこれを例でカバーしていません。組み込み機能はリスト項目を自動的にドラッグします。これをオーバーライドしたい場合は、ハンドラーがリスト自体に設定されていることがわかります。私が具体的にやりたいことは、TileList に、大きなキャンバスにドラッグできるアイテムの小さなサムネイルが表示されることです。リストから項目をドラッグすると、ドラッグ プロキシは別の画像になるはずです。

したがって、提案された手法に従いましたが、プロキシ イメージの幅/高さを明示的に設定した場合にのみ機能します。なんで?

4

2 に答える 2

3

あなたがそれを試すまでは明らかではありません=)私はほんの数週間前に同じことで苦労しました. これが私の解決策でした:

リスト:

<List>
  <mouseDown>onListMouseDown(event)</mouseDown>
</Tree>

マウス ダウン ハンドラー:

private function onMouseDown( event : MouseEvent ) : void {
  var list : List = List(event.currentTarget);

  // the data of the clicked row, change the name of the class to your own
  var item : MyDataType = MyDataType(list.selectedItem);

  var source : DragSource = new DragSource();

  // MyAwsomeDragFormat is the key that you will retrieve the data by in the
  // component that handles the drop
  source.addData(item, "MyAwsomeDragFormat");

  // this is the component that will be shown as the drag proxy image
  var dragView : UIComponent = new Image();

  // set the source of the image to a bigger version here
  dragView.source = getABiggerImage(item);

  // get hold of the renderer of the clicked row, to use as the drag initiator
  var rowRenderer : UIComponent = UIComponent(list.indexToItemRenderer(list.selectedIndex));

  DragManager.doDrag(
    rowRenderer,
    source,
    event,
    dragView
  );
}

ユーザーがリスト内の項目をクリックすると、ドラッグが開始されます。dragEnabledすべて自分で処理するため、リストにあるその他のドラッグ関連のプロパティは設定していないことに注意してください。

これをイベント ハンドラーの先頭に追加すると便利です。

if ( event.target is ScrollThumb || event.target is Button ) {
  return;
}

ユーザーがスクロールバーのどこかをクリックした場合に短絡するだけです。あまりエレガントではありませんが、仕事はします。

于 2008-09-16T18:37:13.800 に答える
1

ここでより簡単な答えを見つけました。この例では DataGrid コントロールを拡張していますが、List コントロールでも同じことができます。私の場合、クラスの代わりに画像ソースを使用します。

public class CustomDragList extends List {

    [Bindable]
    public var dragProxyImageSource:Object;

    override protected function get dragImage():IUIComponent {
        var image:Image = new Image();
        image.width = 50;
        image.height = 50;
        image.source = dragProxyImageSource;
        image.owner = this;
        return image;
    }
}

次に、そのカスタム リストを次のように使用します。

<control:CustomDragList
    allowMultipleSelection="true"
    dragEnabled="true" 
    dragProxyImageSource="{someImageSource}"
    dragStart="onDragStart(event)"/>

'someImageSource' は、イメージ ソース (埋め込み、リンクなど) に通常使用するものであれば何でもかまいません。

于 2010-02-02T15:20:41.357 に答える