air drag and drop

38
Unraveling the hassle of Drag and Drop in AIR Michael Labriola Digital Primates

Upload: michaellabriola

Post on 19-May-2015

6.208 views

Category:

Sports


0 download

DESCRIPTION

An overview of similarities, use cases and differences between drag and drop in Adobe AIR and Adobe Flex.

TRANSCRIPT

Page 1: Air Drag And Drop

Unraveling the hassle of

Drag and Drop

in AIR

Michael LabriolaDigital Primates

Page 2: Air Drag And Drop

Who are you?

Michael LabriolaSenior Consultant at Digital Primates

Flex GeekComponent DeveloperFlex Team Mentor

Page 3: Air Drag And Drop

What is this session about?

AIR provides the ability to drag and drop between objects in the same application, between applications and between the desktop and the operating system.

Understanding the nuances of doing so is the goal of this session

Page 4: Air Drag And Drop

Standard Disclaimer

I am going to lie to you a lot…

There is much more detail than I can cover

Sometimes it is easier to reduce complexity when you start learning a concept and add later…

Page 5: Air Drag And Drop

Two Main Classes

This session is going to talk about:

DragManagerNativeDragManager

Both are responsible for initiating, accepting and presenting feedback for drag and drop

Page 6: Air Drag And Drop

DragManager

We will discuss DragManager first, then the differences between NativeDragManager and DragManager and then finally reveal… well you have to wait for that part.

Page 7: Air Drag And Drop

DragManager

The DragManager is native to the Flex API and handles all the internal drag-and-drop actions in an application, but it has no effect outside of the application window.

Page 8: Air Drag And Drop

Drag and Drop Support

All Flex components have some level of support for drag-and-drop operations.

On most, it is up to the developer to handle the specific user actions (such as mouse down, drag enter, and so on) and properly use the DragManager to handle them.

Page 9: Air Drag And Drop

Vocabulary Lesson

Drag Initiator—The interactive object that begins the drag action and also dispatches the dragStart and dragComplete events.

Drag Proxy—The visual representation of the item being dragged that follows your cursor. Usually it is depicted as a faded silhouette of the object, but it can be customized by the user as well. DragManager can assign any InteractiveObject to be the proxy.

Page 10: Air Drag And Drop

Vocab – Part II

Drop Target—A visual object where a dragged item can be dropped. The drop target makes the final decision on whether the type of object being dragged can be dropped at this location.

Page 11: Air Drag And Drop

Drag and Drop Events

dragEnter—The event dispatched when an item is dragged over a possible drop target. As you will see, this event is often used with the DragManager.acceptDrop() method to grant an object permission to be dropped.

Page 12: Air Drag And Drop

Events II

dragOver—The event dispatched repeatedly as the item is dragged over an interactive object.

dragExit—The event dispatched when the dragged item leaves an interactive object.

dragDrop—The event dispatched when the mouse is released over an eligible drop target. The event handler will be able to access the dropped data by using the event.dragSource object.

Page 13: Air Drag And Drop

Events III

dragComplete—The event dispatched from the drag initiator when the drop is completed. This event allows you to gather feedback on the success of the drop as well as clean up data in the drag initiator.

Page 14: Air Drag And Drop

Example 1

Dragging between two simple lists

dragEnabled, dropEnabled, and dragMoveEnabled

Page 15: Air Drag And Drop

Handling Events

The fully automated process is a great quick way to move/copy data but it provides almost no control over the operation.

Further, it only works between List controls.

To manually implement this process, you handle the events yourself

Page 16: Air Drag And Drop

Drag Source

Internally, DragManager keeps all the data being dragged in an instance of the DragSource class.

This DragSource instance contains one or more copies of the data in different formats.

Page 17: Air Drag And Drop

Drag Source II

For example, the same data could be dragged as text, as an image, or perhaps as HTML.

When the dragged item is dropped, the instance of the DragSource class containing this data is available via the dragSource property of the DragEvent event.

Page 18: Air Drag And Drop

dataForFormat()

The data inside dragSource is retrieved by using the dataForFormat() function of the dragSource, which accepts a string as an argument.

Page 19: Air Drag And Drop

Example 2

Dragging between a list and a Label

dragEnter and dragDrop events

Page 20: Air Drag And Drop

Buidling your own Source

The previous examples both rely upon a List control to start the drag process.

If you are using a non-list-based control or simply want more control, you can begin this process yourself and build your own dragSource

Page 21: Air Drag And Drop

New DragSource

You handle these steps manually by listening for the mouseDown (or other mouse events) on the item being dragged and (mininally) dragEnter and dragDrop on the control receiving the drag.

In response to a mouse down, you create a new DragSource() instance and use a method named addData() to add the data being dragged.

Page 22: Air Drag And Drop

Example 3

Dragging between a label and a list

dragEnter and dragDrop events. dragSource and DragManager.

Page 23: Air Drag And Drop

Between the OS and AIR

Up to now, we have discussed drag and dropping that works in either Flex or AIR.

It is now time to discuss the basics of interacting with the operating system

Page 24: Air Drag And Drop

OS Integration

When building an AIR application that allows users to drag items to and from the OS, you will need to use the NativeDragManager class

NativeDragManager handles the dragged items a bit differently.

Page 25: Air Drag And Drop

Native Drag

It uses the computer’s clipboard to pass data between objects, rather than passing the data in a dragSource object.

Further, it imposes additional security restrictions as you are moving data in and out of an application.

Page 26: Air Drag And Drop

Native Events

nativeDragEnter—The event dispatched when an item is dragged over a possible drop target. As you will see, this event is often used with the NativeDragManager.acceptDrop() method to grant an object permission to be dropped.

Page 27: Air Drag And Drop

Events II

nativeDragOver—The event dispatched repeatedly as the item is dragged over an interactive object.

nativeDragExit—The event dispatched when the dragged item leaves an interactive object.

nativeDragDrop—The event dispatched when the mouse is released over an eligible drop target. The event handler will be able to access the dropped data by using the clipboard.

Page 28: Air Drag And Drop

Events III

nativeDragComplete—The event dispatched from the drag initiator when the drop is completed. This event allows you to gather feedback on the success of the drop as well as clean up data in the drag initiator.

nativeDragUpdate—Used by the initiator to update its state during the various gestures

Page 29: Air Drag And Drop

Differences

Unlike the component-level drag-and-drop operations, there are unknowns when using drag and drop with the OS.

For example, when an item is dragged into the application from the OS, the drag initiator is not a Flex UI control and is unknown to AIR.

Page 30: Air Drag And Drop

Differences

Because the drag initiator is responsible for broadcasting start and complete events, you will not be able to capture a nativeDragStart or nativeDragComplete event.

Similarly, when you are dragging from the application to the OS, you will not receive nativeDragEnter, nativeDragDrop, or nativeDragOver events

Page 31: Air Drag And Drop

Differences

The major difference is the approach used when checking for the existence of a format. In the DragManager examples, the hasFormat() method was called on the dragSource object. In this example, the hasFormat() method is called on the clipboard.

Page 32: Air Drag And Drop

Example 4

Dragging between a desktop and app

nativeDragEnter and nativeDragDrop events. dragSource versus clipboard.

Page 33: Air Drag And Drop

Outbound

Similar differences exist when putting data into the clipboard to send it to the desktop.

Remember, the clipboard is always the transfer mechanism

Page 34: Air Drag And Drop

Example 5

Dragging between an app and the desktop

nativeDragEnter and nativeDragDrop events. dragSource versus clipboard.

Page 35: Air Drag And Drop

The Truth

In AIR NativeDragManager implements the DragManager functionality.

This can be problematic as NativeDragManager isn’t as fully featured

Page 36: Air Drag And Drop

The Way

Andrew Westberg – Flex Junkhttp://www.flexjunk.com/2008/04/08/using-

both-native-and-flex-dragmanager-in-air-10/

Page 37: Air Drag And Drop

Q & A

Seriously? You must have some questions by now?

Page 38: Air Drag And Drop

Resources

Blog Aggregator (All of the Digital Primates)http://blogs.digitalprimates.net/

My Blog Specificallyhttp://blogs.digitalprimates.net/codeSlinger/

Andrew Westberg – Flex Junkhttp://www.flexjunk.com/2008/04/08/using-both-

native-and-flex-dragmanager-in-air-10/