nwebb

Flex, Flash, AIR

Archive for February, 2008

AIR

Apologies for the lack of posts/tutorials over the past 5 months. Since October I've been working flat-out to help deliver the next major release of our software. Now it's done (hurrah) and I've got a little bit of breathing space before we start on the list for the next release! I thought I'd use that chance to tinker with AIR...

Below is the code for my very first file - nothing mind-blowing ;) It simply lists the directories to which any AIR application has read [and/or write] permissions (as clickable links). It also creates a new directory within the user's Documents directory, called AIRcuts:

Actionscript:
  1. <mx:windowedapplication xmlns:mx="http://www.adobe.com/2006/mxml">
  2.     layout="absolute" creationComplete="cc()"&gt;
  3.  
  4.     <mx:script>
  5.         <!--[CDATA[
  6.             private function cc():void
  7.             {
  8.                 //get file directories:
  9.                 var appDir:File = File.applicationDirectory;
  10.                 var appStoreDir:File = File.applicationStorageDirectory;
  11.                 var desktopDir:File = File.desktopDirectory;
  12.                 var docDir:File = File.documentsDirectory;
  13.                 var userDir:File = File.userDirectory;
  14.                 var rootDirArr:Array = File.getRootDirectories();
  15.  
  16.                 //list directories:
  17.                 debug(appDir.nativePath, "Application");
  18.                 debug(appStoreDir.nativePath, "Application Storage");
  19.                 debug(desktopDir.nativePath, "Desktop");
  20.                 debug(docDir.nativePath, "Documents");
  21.                 debug(userDir.nativePath, "User Directory");
  22.  
  23.                 //create new directory:
  24.                 var newDirName:String = "AIRcuts";
  25.                 debug(newDirName, "Creating new directory...");
  26.                 var dirToCreate:File = userDir.resolvePath(newDirName);
  27.                 dirToCreate.createDirectory();
  28.                 var d:File = userDir.resolvePath(newDirName);
  29.                 debug(d.nativePath, "Newly Created Directory");
  30.  
  31.                 //list root directories:
  32.                 for each(var dir:File in rootDirArr)
  33.                 {
  34.                     debug(dir.nativePath, "RootDir");
  35.                 }
  36.             }
  37.  
  38.             private function debug(str:String, prepend:String=""):void
  39.             {
  40.                    //all n's below should have a backslash before them 
  41.                                debugTA.htmlText += prepend + ":n" + "<font color='#0000FF'><a href='file:///" + str + "'>" + str + "</a></font>nn";
  42.             }
  43.         ]]-->
  44.     </mx:script>
  45.     <mx:textarea id="debugTA" left="10" right="10" top="10" bottom="10">
  46. </mx:textarea>
  47. </mx:windowedapplication>

If IE is set to be your default browser then the links will open up a new Explorer window, but if FireFox is the default browser then the directory contents will be listed in a FF browser window. I guess this is due to the tight integration between Explorer and IExplorer and there is no way around this (I'd like directories to open up in explorer, regardless). I have no idea what happens if you use other browsers, or if you're on a mac - let me know :)

Anyway, as you can see the example doesn't do an awful lot, but it's a starting point, and if you're new to AIR, feel free to use it as such. Hopefully I'll get time to expand this in to something useful, but that depends on what free time I get.

No comments

Peter Ent’s post on creationPolicy vs Binding

Peter Ent has long been one of my favourite Flash platform bloggers. His posts are clear and informative.

I wanted to link to this particular post for a couple of reasons: It is a good introduction to two-way binding for those not familiar with the BindingUtils class/Binding tag; It provides a lovely example of when two-way binding comes in useful, and most of all because it advocates the best practise of not binding directly to a component in order to get/set your data ( you instead use a model/value object or bindable variable ). This layer of abstraction promotes loose coupling, giving you more freedom to swap your component for another as you see fit; and here Peter demonstrates another reason to follow that practice - how to read from and write to multiple components within a form, without the need to instantiate all of the child components upfront by changing the creationPolicy of a multi-view component such as the Accordion.

No comments

Bad Behavior has blocked 399 access attempts in the last 7 days.