I've seen examples that use a timer, get the file list, and check each file for changes, but is there a simpler way to do this such as...
<mx:FileSystemList id="fs" visible="false" />
private function onCreationComplete():void
{
fs.directory = File.applicationDirectory.resolvePath('../../assets');
if (fs.directory.exists)
addEventListener(FileEvent.DIRECTORY_CHANGE, onDirectoryChange);
}
priva开发者_如何学Cte function onDirectoryChange(e:FileEvent):void
{
trace("file was changed");
}
This doesn't seem to fire when a file changes
Use the FileMonitor class.
http://www.mikechambers.com/blog/2009/03/11/monitoring-file-changes-in-adobe-air/
Code from the tutorial:
import com.adobe.air.filesystem.FileMonitor;
import flash.filesystem.File;
import flash.events.Event;
import com.adobe.air.filesystem.events.FileMonitorEvent;
private var monitor:FileMonitor;
private function onSelectButtonClick():void
{
var f:File = File.desktopDirectory;
f.addEventListener(Event.SELECT, onFileSelect);
f.browseForOpen("Select a File to Watch.");
}
private function onFileSelect(e:Event):void
{
var file:File = File(e.target);
if(!monitor)
{
monitor = new FileMonitor();
monitor.addEventListener(FileMonitorEvent.CHANGE, onFileChange);
monitor.addEventListener(FileMonitorEvent.MOVE, onFileMove);
monitor.addEventListener(FileMonitorEvent.CREATE, onFileCreate);
}
monitor.file = file;
monitor.watch();
}
private function onFileChange(e:FileMonitorEvent):void
{
trace("file was changed");
}
private function onFileMove(e:FileMonitorEvent):void
{
trace("file was moved");
}
private function onFileCreate(e:FileMonitorEvent):void
{
trace("file was created");
}
精彩评论