mardi 23 février 2016

NativeProcess communication giving error

I am trying to communicate to a python script through actionscript. it gives me error on line "var stdOut:ByteArray = process.standardOutput;" Error is: Implicit coercion of a value with static type IDataInput to a possibly unrelated type ByteArray. I am following the same approach as on Adobe's page:

package
{
    import flash.display.Sprite;
    import flash.desktop.NativeProcessStartupInfo;
    import flash.filesystem.File;
    import flash.desktop.NativeProcess;
    import flash.events.ProgressEvent;
    import flash.utils.ByteArray;

    public class InstaUtility extends Sprite
    {
        public var nativeProcessStartupInfo:NativeProcessStartupInfo = new     NativeProcessStartupInfo();
        public var file:File = new File("C:/Python27/python.exe");
        public var process:NativeProcess = new NativeProcess();
        public function InstaUtility()
        {
            nativeProcessStartupInfo.executable = file;
            nativeProcessStartupInfo.workingDirectory =     File.applicationDirectory.resolvePath(".");
            trace("Location " + File.applicationDirectory.resolvePath(".").nativePath);
            var processArgs:Vector.<String> = new Vector.<String>();
            processArgs[0] = "test.py";
            nativeProcessStartupInfo.arguments = processArgs;
            var process:NativeProcess = new NativeProcess();
            process.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, onOutputData); 
            process.start(nativeProcessStartupInfo); 
        }   
        public function onOutputData(event:ProgressEvent):void 
        { 
            var stdOut:ByteArray = process.standardOutput; //error
            var data:String = stdOut.readUTFBytes(process.standardOutput.bytesAvailable); 
            trace("Got: ", data); 
        }

    }
}

3 commentaires:

  1. Ce commentaire a été supprimé par l'auteur.

    RépondreSupprimer
  2. This will work without error:

    public function onOutputData(event:ProgressEvent):void
    {
    var process: NativeProcess = event.target as NativeProcess;
    var count: uint = process.standardOutput.bytesAvailable;
    trace("Bytes Available=" + count);
    var data: String = process.standardOutput.readUTFBytes(process.standardOutput.bytesAvailable);
    trace("Got: ", data);
    }

    RépondreSupprimer
  3. or try:
    import flash.utils.IDataInput;
    var stdOut:IDataInput = process.standardOutput;

    RépondreSupprimer