The drag-and-drop operation lets you move data from one place in an Adobe® Flex™ application to another. It is especially useful in a visual application where you can drag data between two lists, drag controls in a container to reposition them, or drag Flex components between containers.
You can add support for drag and drop to all Flex components. Flex also includes built-in support for the drag-and-drop operation for certain controls such as List, Tree, and DataGrid, that automate much of the processing required to support drag and drop.
The drag-and-drop operation has three main stages: initiation, dragging, and dropping:
Dragging DroppingThe following controls include built-in support for the drag-and-drop operation:
The built-in support for these controls lets you move items by dragging them from a drag-enabled control to a drop-enabled control. However, to copy items, you must add additional logic.
For all list classes except the Tree control, the default value of the dragMoveEnabled property is false, so you can only copy elements from one control to the other. By setting the dragMoveEnabled to true in the first List control, you can move and copy data. For the Tree control, the default value of the dragMoveEnabled property is true.
When the dragMoveEnabled property is set to true, the default drag-and-drop action is to move the drag data. To perform a copy, hold down the Control key during the drag-and-drop operation.
The only requirement on the drag and drop operation is that the structure of the data providers must match for the two controls. In this example, the data provider for srclist is an Array of Strings, and the data provider for the destination List control is an empty Array. If the data provider for destlist is an Array of some other type of data, destlist might not display the dragged data correctly.
You can modify the dragged data as part of a drag-and-drop operation to make the dragged data compatible with the destination.
You can use drag and drop to copy data between two different types of controls, or between controls that use different data formats. To handle this situation, you write an event handler for the dragDrop event that converts the data from the format of the drag initiator to the format required by the drop target.
Drag and drop properties for list-based controls
| Property/Method | Description |
|---|---|
| dropIndicatorSkin | Specifies the name of the skin to use for the drop-insert indicator which shows where the dragged data will be inserted. The default value is ListDropIndicator. |
| dragEnabled | A Boolean value that specifies whether the control is a drag initiator. The default value is false. When true, users can drag selected items from the control. When a user drags items from the control, Flex creates a DragSource object that contains the following data objects:
|
| dropEnabled | A Boolean value that specifies whether the control can be a drop target that uses default values for handling items dropped onto it. The default value is false, which means that you must write event handlers for the drag events. When the value is true, you can drop items onto the control by using the default drop behavior. When you set dropEnabled to true, Flex automatically calls the showDropFeedback() and hideDropFeedback() methods to display the drop indicator. |
| dragMoveEnabled | If the value is true, and the dragEnabled property is true, specifies that you can move or copy items from the drag initiator to the drop target. When you move an item, the item is deleted from the drag initiator when you add it to the drop target. If the value is false, you can only copy an item to the drop target. For a copy, the item in the drag initiator is not affected by the drop. When the dragMoveEnabled property is true, you must hold down the Control key during the drop operation to perform a copy. The default value is false for all list controls except the Tree control, and true for the Tree control. |
| calculateDropIndex | Returns the item index in the drop target where the item will be dropped. Used by the dragDrop event handler to add the items in the correct location. Not available in the TileList or HorizontalList controls. |
| hideDropFeedback() | Hides drop target feedback and removes the focus rectangle from the target. You typically call this method from within the handler for the dragExit and dragDrop events. |
| showDropFeedback() | Specifies to display the focus rectangle around the target control and positions the drop indicator where the drop operation should occur. If the control has active scroll bars, hovering the mouse pointer over the control's top or bottom scrolls the contents. You typically call this method from within the handler for the dragOver event. |
No comments:
Post a Comment