Launching Files from Adobe Air

So, this takes the long way around, and is not a good solution for mass-distributed applications, but if you’re lucky enough to have a managed environment that you can push installs down the pipe, this is a way to let your users launch files from AIR.

First, download Switchboard.

Second, add Switchboard to your libs.

Third, use this script:

      private function openFile(f:File):void{
        Client.init(super.applicationID);
        var message:Message = new Message();
        var script:String = "var runScript = function(fileName){\n" +
                  "   var theFile = new File(fileName);\n" +
                  "  if(!theFile.exists) return false;\n" +
                  "  theFile.execute();\n" +
                  "}\n" +
                  "runScript(\"" + f.url.substr(7) + "\");";
        message.body = script;
        message.target = "bridge";
        message.onError =  function( msg: Message ) : void {
          // put the error message into the result box
          trace("Error: " + msg.body);
        }
 
        message.send();
        status = "Opening " + f.name;
        Client.close();
      }

This opens up bridge, then uses Bridge to run the “execute()” command that ExtendScript (or whatever they’re calling it) has available.

Now… while this is neither simple or elegant, it gets the job done. I’d rather use Merapi, but my app has to ship before Merapi can go stable.

1 comment so far ↓

#1 Launching Files from Adobe Air « Rich Internet Applications on 09.05.08 at 9:41 am

[...] Source [...]

You must log in to post a comment.