Adobe Air - opening a file with air

So, I created an Air application that saves the type of custom file. I have established file associations when I publish the application, and when you double-click on the file, it opens the air application. What are the hooks for me to discover that an application has been opened through a file? Obviously, I need to detect this, and then get the application to open the file itself.

+4
source share
2 answers

Listen to InvokeEvent , which will hold the requested file name in the arguments property:

Quick mxml example:

 <?xml version="1.0"?> <mx:WindowedApplication xmlns:mx="http://www.adobe.com/2006/mxml" xmlns:s="spark.components.*" invoke="onAppInvoke(event);"> <mx:Script><![CDATA[ import mx.controls.Alert; private function onAppInvoke(event:InvokeEvent):void { if (event.arguments.length>0) { // ok app call with an arguments var fileName:String=event.arguments[0]; Alert.show("app open with : "+fileName); } else { // app open normally Alert.show("normal launch"); } } ]]></mx:Script> </mx:WindowedApplication> 
+4
source

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

The NativeApplication application's NativeApplication object dispatches an invoke event when the application is called.

The NativeApplication object always dispatches an invoke event when the application starts, but the event can also be dispatched at other times. For example, a running application sends an additional InvokeEvent when a user activates a file associated with the application.

You can run only one instance of a specific application. Subsequent attempts to launch the application will result in a new invoke event dispatched by the NativeApplication object of the running instance. It is the application’s responsibility to handle this event and take appropriate measures, such as opening a new application window to display data in a file.

The objects

InvokeEvent dispatched by a NativeApplication object ( NativeApplication.nativeApplication ). To receive calls, call the addEventListener() method of the addEventListener() object. When an event logger is logged for an invoke event, it will also receive all invoke events that occurred before registration. These earlier events are dispatched after the addEventListener() call addEventListener() , but not necessarily before the new call event that can be dispatched after registration. Therefore, you should not rely on the 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> 
+5
source

All Articles