AS3: Drag n Drop


/ Published in: ActionScript 3
Save to your folder(s)

Lee is a genious


Copy this code and paste it in your HTML
  1. /*****************************
  2. import Classes
  3. *****************************/
  4. import fl.video.FLVPlayback;
  5. //Drag and Drop Manager
  6. import flash.desktop.DragManager;
  7. import flash.desktop.ClipboardFormats;
  8. //Event that Handles the Drag and Drop Events
  9. import flash.events.NativeDragEvent;
  10.  
  11.  
  12. /*****************************
  13. Create an active Hit Spot
  14. *****************************/
  15. var shape:Shape = new Shape();
  16. shape.graphics.beginFill(0x000000, 1);
  17. shape.graphics.drawRect(0, 0, stage.stageWidth, stage.stageHeight);
  18. shape.graphics.endFill();
  19.  
  20. var _mc:MovieClip = new MovieClip();
  21. _mc.addChild(shape);
  22. addChild(_mc);
  23.  
  24. var video_vd:FLVPlayback = new FLVPlayback();
  25. addChild(video_vd);
  26. video_vd.x = 0;
  27. video_vd.y = 0;
  28. video_vd.width = 320;
  29. video_vd.height = 240;
  30.  
  31.  
  32. /*****************************
  33. Drag and Drop
  34. *****************************/
  35. this.addEventListener(NativeDragEvent.NATIVE_DRAG_ENTER, onDragEnter);
  36. function onDragEnter(e:NativeDragEvent):void {
  37. //NativeDragEvent has a clipboard property where our data is stored. That clipboard class has a getData method
  38. //The way to specifiy formats is the a constant of a ClipboardFormats class. We just want a file object
  39. //The reason it is a filelist is because if multiple files were dragged into the Flash, all of them could be retreived
  40. var fa:Object = e.clipboard.getData(ClipboardFormats.FILE_LIST_FORMAT);
  41. //Check the File Extension of the Object
  42. if (fa[0].extension == "flv") {
  43. //Accept the Drag n Drop operation
  44. DragManager.acceptDragDrop(this);
  45. }
  46. }
  47.  
  48. this.addEventListener(NativeDragEvent.NATIVE_DRAG_DROP, onDragDrop);
  49. function onDragDrop(e:NativeDragEvent):void {
  50. var fa:Object = e.clipboard.getData(ClipboardFormats.FILE_LIST_FORMAT);
  51. video_vd.play(fa[0].url);
  52. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.