所以我创建了一个保存为自定义文件类型的 Air 应用程序。我在发布应用程序时设置了文件关联,当您双击文件时,它会打开 air 应用程序。我检测到应用程序已通过文件打开的钩子(Hook)是什么?显然,我需要检测到这一点,然后让应用程序自行打开文件。
最佳答案
收听invoke
WindowedApplication上的事件或其nativeApplication .它有一个 arguments保存在此调用期间传递的字符串参数的数组属性。
The
NativeApplication
object of an AIR application dispatches aninvoke
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 additionalInvokeEvent
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 theNativeApplication
object (NativeApplication.nativeApplication
). To receive invoke events, call theaddEventListener()
method of theNativeApplication
object. When an event listener registers for an invoke event, it will also receive allinvoke
events that occurred before the registration. These earlier events are dispatched after the call toaddEventListener()
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>
关于apache-flex - Adobe Air - 使用 Air 打开文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3634278/