2). If you have old project just go on WindowedApplication's xml page in that change
first line to
"<" application xmlns="http://ns.adobe.com/air/application/2.0" ">"
also add extra attribute if not available.
"<" supportedProfiles ">" extendedDesktop "<" / supportedProfiles ">"
Now your application is capable to run native process and open any exe or dmg file through native process.
I just create below class for open photoshop via AIR application. For getting response from photoshop's here one file photoshopRead.txt is created through javascript. When process is finish this file is write a return result and in action script site timer is check response and read this file so we get finished return result.
I hope this will use full everyone who want to call a window application through AIR.
package com.ysi.manager
{
import flash.desktop.NativeProcess;
import flash.desktop.NativeProcessStartupInfo;
import flash.events.IOErrorEvent;
import flash.events.ProgressEvent;
import flash.events.TimerEvent;
import flash.filesystem.File;
import flash.filesystem.FileMode;
import flash.filesystem.FileStream;
import flash.system.System;
import flash.utils.Timer;
import flash.utils.setTimeout;
public class MgrPhotoshopCalling
{
// Variable Declaration
private var photoshopExePath:String = "C://Program Files//Adobe//Adobe Photoshop CS4//Photoshop.exe";
private var jsFileToCall:String = "D:\\FlexProjectSVN\\YSIPrototype\\src\\FinishLayoutToPhotoshop.js";
private var responseFileWrite:String = "C:/wxyz.txt";
private var procarg:Vector.
private var returnHandler:Function;
private var fileCreate:File;
private var filePR:File;
// VARIABLE OF PROCESS
private var process:NativeProcess;
private var nativeProcessStartupInfo:NativeProcessStartupInfo;
private var filePhotoshop:File;
// TIMER VARIABLE
private var timer : Timer;
private var fileResponse:File;
private var fileStream : FileStream;
private var responseCheckstr : String ;
private var currentScriptExecutedTime : String;
public function callPhotoShop(scriptData:String,retFunction:Function):void
{
var isErr:Boolean = false;
returnHandler = retFunction;
if(NativeProcess.isSupported)
{
filePhotoshop = new File(photoshopExePath);
if(filePhotoshop.exists)
{
fileResponse = new File(responseFileWrite);
if(fileResponse.exists)
{
fileResponse.deleteFile();
}
fileResponse = null;
filePR = new File(File.applicationDirectory.nativePath + "/data/scriptFile/photoshopRead.txt");
responseFileWrite = filePR.url;
filePR = null;
fileCreate = new File(File.applicationDirectory.nativePath + "/data/scriptFile/photoshopExectue.js");
// CRETE PHOTOSHOP EXECUTE FILE IN PATH
var fswrite:FileStream = new FileStream();
fswrite.open(fileCreate, FileMode.WRITE);
fswrite.writeMultiByte(scriptData, 'utf-8');
fswrite.close();
fswrite = null;
jsFileToCall = fileCreate.nativePath;
// Create native startup info
nativeProcessStartupInfo = new NativeProcessStartupInfo();
nativeProcessStartupInfo.executable = filePhotoshop;
// Create Vector array to passing a artument
procarg = new Vector.
procarg.push("start");
procarg.push(jsFileToCall);
nativeProcessStartupInfo.arguments = procarg; // Set Native Proegress Argument
// Create native process object for calling a exe / system's executable file
process = new NativeProcess();
// SET ERROR HANDLER
process.addEventListener(ProgressEvent.STANDARD_ERROR_DATA ,onError,false,0,true);
process.addEventListener(IOErrorEvent.STANDARD_ERROR_IO_ERROR ,onError,false,0,true);
process.addEventListener(IOErrorEvent.STANDARD_INPUT_IO_ERROR ,onError,false,0,true);
process.addEventListener(IOErrorEvent.STANDARD_OUTPUT_IO_ERROR ,onError,false,0,true);
process.addEventListener(ProgressEvent.STANDARD_ERROR_DATA ,onError,false,0,true);
// CALL NATIEVE PROCESS
process.start(nativeProcessStartupInfo);
timerCallStart();
}
else
{
trace("Photoshop's Executable file not found....");
isErr = true;
}
}
else
{
isErr = true;
}
if(isErr && returnHandler != null)
{
returnHandler();
}
}
private function onError(event:*):void
{
trace("Error....\nEvent:..."+ event.type);
if(returnHandler != null)
{
returnHandler();
}
}
private function getJsResponse(event : TimerEvent):void
{
fileResponse = new File(responseFileWrite);
if(fileResponse.exists)
{
currentScriptExecutedTime = fileResponse.modificationDate.time.toString();
if(fileStream != null)
{
fileStream = null;
}
fileStream = new FileStream();
fileStream.open(fileResponse, FileMode.READ);
if(currentScriptExecutedTime != "")
{
responseCheckstr = String(fileStream.readUTFBytes(fileStream.bytesAvailable));
timer.removeEventListener(TimerEvent.TIMER,getJsResponse);
timer.stop();
timer = null;
fileStream.close();
fileStream = null;
setTimeout(removeResponseFile,10);
}
}
else
{
trace("YSI Response file not found....");
}
}
// START TIMER
private function timerCallStart():void
{
timer = new Timer(1000,0);
timer.addEventListener(TimerEvent.TIMER,getJsResponse);
timer.start();
}
// REMOVE TEMPORARY FILE AND CALL RETURN FUNCTION
private function removeResponseFile():void
{
// DELETE RESPONSE FILE
if(fileResponse && fileResponse.exists)
{
fileResponse.deleteFile();
}
// DELETE PHOTOSHOP EXECUTABLE FILE
if(fileCreate && fileCreate.exists)
{
fileCreate.deleteFile();
}
// CALL RETURN FUNCTION
if(returnHandler != null)
{
returnHandler(responseCheckstr);
}
// CLEAR VARIABLE
procarg = null;
returnHandler = null;
// VARIABLE OF PROCESS
process = null;
nativeProcessStartupInfo = null;
filePhotoshop = null;
// TIMER VARIABLE
timer = null;
fileResponse = null;
fileCreate = null;
fileStream = null;
System.gc();
}
}
}