2 Replies Latest reply on Nov 5, 2008 7:57 PM by ReisenderJosh

    Drag and drop external text into a Flex component

    ReisenderJosh
      Hi,

      is there any way to allow drag and drop of external text (for example, selected text from another browser or even from the address bar) into a Flex component like TextArea? I know how to drag and drop between two different Flex components but in this case, the source is external. There must be something I can do to TextArea like its dragdrop property to allow this feature... any help would be greatly appreciated.

      Thanks,
      Josh
        • 1. Re: Drag and drop external text into a Flex component
          thebouv Level 2
          Short answer: Yes, as long as it is an AIR app.

          Browser-based Flex apps do not have access to ClipBoardFormats, so I'm not sure it is possible to do what I think you want to do -- have a web-based Flex app that allows you to drag and drop selected text from other apps. Most possibly because of the security sandbox that the Flash player runs in.

          However, if you wanted to do it in an AIR app, I built this as an example for you (you can view a "cleaner" version with proper indents at http://pastebin.com/f741cbac8 ):

          <?xml version="1.0" encoding="utf-8"?>
          <mx:WindowedApplication xmlns:mx=" http://www.adobe.com/2006/mxml"
          creationComplete="initDandD();" width="500" height="600">

          <mx:Script>
          <![CDATA[

          public function initDandD():void {
          addEventListener(NativeDragEvent.NATIVE_DRAG_ENTER, onDragIn);
          addEventListener(NativeDragEvent.NATIVE_DRAG_DROP, onDragDrop);
          }

          private function onDragIn(e:NativeDragEvent):void {
          if(e.clipboard.hasFormat(ClipboardFormats.TEXT_FORMAT)) {
          NativeDragManager.acceptDragDrop(this);
          }
          }

          private function onDragDrop(e:NativeDragEvent):void {
          var myString:String = e.clipboard.getData(ClipboardFormats.TEXT_FORMAT) as String;

          myTextArea.text = myString;
          }

          ]]>
          </mx:Script>
          <mx:TextArea id="myTextArea" width="326" height="262"/>
          </mx:WindowedApplication>
          • 2. Re: Drag and drop external text into a Flex component
            ReisenderJosh Level 1
            That's unfortunate but it makes sense for Flash to have that security feature. Thanks for the help - I'll probably just have to settle with Copy and Paste if I am to do this in a web app.