Search Flex Components Free

Custom Search

December 19, 2007

Flex Examples

Flex Examples: I thought I will post this as there has been a lot of API changes between Beta2 & Beta3. I will try to compile some info on the migration from Beta2 to Beta3.
For now, one of the major changes affecting this particular scenario is the fact that flash.Desktop.DragManager has now been renamed as flash.desktop.NativeDragManager. Here is how you can achieve the drag & drop of file(s) from desktop. The app actually accepts an image file on drag & drop from desktop and displays it in an Image control.
import NativeDragManager & NativeDragEvent
add event listeners for NativeDragEvent.NATIVE_DRAG_ENTER and NativeDragEvent.NATIVE_DRAG_DROP
In the DRAG_ENTER handler, you call NativeDragManager.acceptDragDrop(this);
In the DRAG_DROP handler, you can get to the file(s) dropped using the following code…
public function onDrop(event:NativeDragEvent):void{var dropfiles:Array = event.clipboard.getData( ClipboardFormats.FILE_LIST_FORMAT) as Array;
Now you can loop through the files using a for… each loop as below
for each (var file:File in dropfiles){
Use the file as required in your app. Here I extract the extension of the file, check if it is an image and then load it in an Image control.
You can find the code of the application here…

Related Flex Tutorials