Simple Flex util component to support dragging files from Desktop into Flex-AIR application.

25
Jul/07
4

I created quickly this component to make your mxml code simpler if you want to support dragging files into your Flex/AIR application.

You would only have to add the FlexAIRDrag tag and link the UIComponent and react to the DropEvent which would occur the moment files are dropped inside the defined UIComponent.

Sample application :

<?xml version=”1.0″ encoding=”utf-8″?>
<mx:WindowedApplication xmlns:mx=”http://www.adobe.com/2006/mxml” xmlns:etech=”com.adobe.etech.*” creationComplete=”this.addEventListener(MouseEvent.MOUSE_DOWN,onMouseDownTitle);” layout=”absolute” >
    <mx:Script>
        <![CDATA[
            import mx.controls.Alert;
            import flash.desktop.DragManager;
            import flash.desktop.DragActions;
            import mx.events.DragEvent;
            import flash.desktop.TransferableData;
            import flash.desktop.TransferableFormats;
            import flash.events.NativeDragEvent;
            import com.adobe.etech.DropEvent;       
            import flash.filesystem.File;   

        private function onMouseDownTitle(evt:MouseEvent):void
        {
            stage.window.startMove();
        }
        private function onDrop(event:DropEvent):void {
            for each (var file:File in event.dropfiles){
                  Alert.show("This file was dragged in window : " + file.name);
            }                               
        }
        ]]>
    </mx:Script>

    <etech:FlexAIRDrag uiComponent=”{panelDrop}” FlexAIRDrag=”onDrop(event)” />

    <mx:Panel id=”panelDrop”  width=”636″ height=”378″/>   
</mx:WindowedApplication>

You can download the source files here.

Filed under: Flex
Comments (3) Trackbacks (1)
  1. John
    9:29 pm on November 7th, 2007

    Lol- I was wondering why ithe feature didn’t come with the release pack. But now I know-its just an on-going project.
    Thanks for your effort.

  2. movearound
    4:37 pm on May 1st, 2008

    1172: Definition flash.desktop:DragManager could not be found.
    1172: Definition flash.desktop:DragOptions could not be found.
    1172: Definition flash.desktop:TransferableData could not be found.
    1172: Definition flash.desktop:TransferableFormats could not be found.

    I’ getting error for these packages. I’m having Air latest version.

  3. chris
    5:16 pm on May 14th, 2008

    im having the same exact issues as you Movearound… any leads?
    thanks

Leave a comment