Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Adobe Air - Opening a File With Air

So I've created an Air app that saves to a custom file type. I've set up the file associations when I publish the app and, when you double click the file it opens the air app. What are the hooks for me to detect that the app has been opened via a file? Obviously, I need to detect this and then get the app to open the file itself.

like image 927
hamishtaplin Avatar asked Jan 22 '23 12:01

hamishtaplin


1 Answers

Listen for the invoke event on the WindowedApplication or its nativeApplication. It has an arguments array property that holds the string arguments passed during this invocation.

The NativeApplication object of an AIR application dispatches an invoke event when the application is invoked.

The NativeApplication object always dispatches an invoke event when an application is launched, but the event may be dispatched at other times as well. For example, a running application dispatches an additional InvokeEvent when a user activates a file associated with the application.

Only a single instance of a particular application can be launched. Subsequent attempts to launch the application will result in a new invoke event dispatched by the NativeApplication object of the running instance. It is an application's responsibility to handle this event and take the appropriate action, such as opening a new application window to display the data in a file.

InvokeEvent objects are dispatched by the NativeApplication object (NativeApplication.nativeApplication). To receive invoke events, call the addEventListener() method of the NativeApplication object. When an event listener registers for an invoke event, it will also receive all invoke events that occurred before the registration. These earlier events are dispatched after the call to addEventListener() returns, but not necessarily before a new invoke event that might be might be dispatched after registration. Thus, you should not rely on dispatch order.

<mx:WindowedApplication creationComplete="init()">
  <mx:Script>
  <![CDATA[
     public function init():void
     {
          NativeApplication.nativeApplication.addEventListener(InvokeEvent.Invoke, onInvoke);
     }
     public function onInvoke(e:InvokeEvent):void
     {
          var args:Array = e.arguments;
          trace("There are " + args.length + " arguments");
          for(var i:int = 0; i < args.length; i++)
          {
               trace("Argument #" + i + " " + args[i]);
          }
     }
  ]]>
  </mx:Script>
</mx:WindowedApplication>
like image 108
Amarghosh Avatar answered Jan 29 '23 08:01

Amarghosh