[Component] Location WatchDog v1.0

It’s been a long time since I posted in my blog. The reason was that I wasn’t actually working actively on any Flex project in my previous job at Nokia. In my new role, I hope to get lots of chances to dabble with my favorite coding language😉 . Anyway, here I am with a new simple and silly component again🙂

I am calling it a Location WatchDog. What it does is pretty simple. It monitors a specific location (folder/directory) for any updates. If any new files are added to the folder, the WatchDog throws an event LocationEvent.FILES_ADDED. The event returns an array of new Files added to the location.

I am still working on it. Need to add some more stuff to it like capability to fire the LocationEvent.FILES_DELETED that returns the list of deleted files. The component allows you to also specify file extensions that you wish to monitor the location for. By default the component only detects normal files, while it also allows you to specify includeSystemFiles attribute as true to force the component to listen to even hidden and system files.

You can download the component in swc from here. The code of the component is checked in at the Google Code.

You can use this component in your code by calling the component in your mxml  – and then doing this in your actionscript-

private function initView():void{
snoopy.fileExtensions = <code>new Array("txt", "abc");</code>
<code>snoopy.locationPath = File.desktopDirectory.nativePath;
snoopy.addEventListener(LocationEvent.FILES_ADDED, getNewFiles);
snoopy.startPinging();
}

private function getNewFiles(event:LocationEvent):void{
var x:Object = event;
}

Nothing fancy. Just simple and plain. As long as it saves someone somewhere some coding time😉. Or is it already part of the framework?😉

(Download: SWC | Source)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: