Similar to the operating system opening a file using its default application, AIR 2.0 provides the ability for applications to launch native processes and interact with them. The following classes add support for these capabilities. Need a useful example that shows that functionality
The application below opens up a text file: foobar.txt using the MacOS TextEdit text editor.
Similar to the operating system opening a file using its default application, AIR 2.0 provides the ability for applications to launch native processes and interact with them. The following classes add support for these capabilities.
flash.events.NativeProcessExitEvent - event dispatched once a
process exits. It is possible that this event will never be
dispatched if the child process outlives the AIR application.
Launching and interacting with native processes will only be
available for applications that are installed using a native OS
installer.
Create a new application and name it NativeProcessExample.
You need to make sure you have enabled the extended desktop
in your descriptor. Open NativeProcessExample-app.xml and add the
following tag:
<supportedProfiles>extendedDesktop</supportedProfiles>
The application below opens up a text file: foobar.txt using
the MacOS TextEdit text editor.
<?xml version="1.0" encoding="utf-8"?>
<s:WindowedApplication xmlns:fx="http://ns.adobe.com/mxml/2009"
xmlns:s="library://ns.adobe.com/flex/spark"
xmlns:mx="library://ns.adobe.com/flex/mx">
<fx:Script>
<![CDATA[
import flash.events.NativeProcessExitEvent;
public function executeNativeProcess():void
{
var executable:File = new
File("/Applications/TextEdit.app/Contents/MacOS/TextEdit");
var workingDirectory:File = new File("/");
var nativeProcess:NativeProcess = new
NativeProcess();
if (NativeProcess.isSupported)
{
trace("Native Process Supported");
}
var
nativeProcessStartupInfo:NativeProcessStartupInfo = new
NativeProcessStartupInfo();
nativeProcessStartupInfo.executable = executable;
nativeProcessStartupInfo.workingDirectory =
workingDirectory;
var args:Vector.<String> = new
Vector.<String>();
args.push("/Users/Elad/Desktop/foobar.txt"); //
open file that was given with the executable application
nativeProcessStartupInfo.arguments = args;
nativeProcess.addEventListener(
NativeProcessExitEvent.EXIT, onExitError );
try {
nativeProcess.start(nativeProcessStartupInfo);
} catch (error:IllegalOperationError) {
trace("Illegal Operation: "+error.toString());
} catch (error:ArgumentError) {
trace("Argument Error: "+error.toString());
} catch (error:Error) {
trace ("Error: "+error.toString());
}
if (nativeProcess.running)
{
trace ("Native Process Support");
}
}
public function
onExitError(event:NativeProcessExitEvent):void
{
trace( "Native Process Exit code: "+event.exitCode
);
}
]]>
</fx:Script>
<s:Button id="button"
label="Open File foobar.txt with text editor"
click="executeNativeProcess();"
width="250" />
</s:WindowedApplication>
To learn more about this feature and more order
AdvancED
Flex 4
+