USB Support in AIR


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



Copy this code and paste it in your HTML
  1. // Download Volume Monitor in Adobe's coreLib from http://code.google.com/p/as3corelib/
  2.  
  3. import com.adobe.air.filesystem.FileMonitor;
  4. import flash.filesystem.File;
  5. import flash.events.Event;
  6. import com.adobe.air.filesystem.events.FileMonitorEvent;
  7.  
  8. private var monitor:FileMonitor;
  9.  
  10. private function onSelectButtonClick():void
  11. {
  12. var f:File = File.desktopDirectory;
  13. f.addEventListener(Event.SELECT, onFileSelect);
  14. f.browseForOpen("Select a File to Watch.");
  15. }
  16.  
  17. private function onFileSelect(e:Event):void
  18. {
  19. var file:File = File(e.target);
  20.  
  21. if(!monitor)
  22. {
  23. monitor = new FileMonitor();
  24. monitor.addEventListener(FileMonitorEvent.CHANGE, onFileChange);
  25. monitor.addEventListener(FileMonitorEvent.MOVE, onFileMove);
  26. monitor.addEventListener(FileMonitorEvent.CREATE, onFileCreate);
  27. }
  28.  
  29. monitor.file = file;
  30. monitor.watch();
  31. }
  32.  
  33. private function onFileChange(e:FileMonitorEvent):void
  34. {
  35. trace("file was changed");
  36. }
  37.  
  38. private function onFileMove(e:FileMonitorEvent):void
  39. {
  40. trace("file was moved");
  41. }
  42.  
  43. private function onFileCreate(e:FileMonitorEvent):void
  44. {
  45. trace("file was created");
  46. }

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.