views:

59

answers:

0

I am starting to work with Air2 NativeProcess and maybe you can give me a hand.

I want to create a project with parts in Java and Flex that communicate through NativeProcess. I already installed Air2 and set it up for Eclipse.

I wrot a small aplication in Flex with two text fields (textToSend and TextReceived) and a button (sendText with function sendData):

private var process:NativeProcess;

            private function init():void
            {
                if (NativeProcess.isSupported)
                {
                    launchJavaApp();
                }
                else
                { 
                    trace("NativeProcess not supported.");
                }       
            }

            private function launchJavaApp():void
            {
                var file:File = File.applicationDirectory;
                file = file.resolvePath("JavaApps");
                file = file.resolvePath("/myJavaApp");


                var nativeProcessStartupInfo:NativeProcessStartupInfo = new NativeProcessStartupInfo();
                nativeProcessStartupInfo.executable = file;

                process = new NativeProcess();
                process.start(nativeProcessStartupInfo);
                process.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, onOutputData);
                process.addEventListener(ProgressEvent.STANDARD_INPUT_PROGRESS, inputProgressListener);
            }
            public function sendData():void
            {
                process.standardInput.writeUTFBytes(textToSend.text + "\n");
            }
            public function inputProgressListener(event:ProgressEvent):void
            {
                process.closeInput();
            }
            public function onOutputData(event:ProgressEvent):void
            {
                textReceived.text = process.standardOutput.readUTFBytes(process.standardOutput.bytesAvailable);
                var date:Date = new Date();
                dateField.text = date.toString();
                launchJavaApp();
            }

This is adapted from This tutorial.

In any case, now I have to create my Java application. What tipe of application should I create? How do I export it? and in there how do I read/write the standard input/output???

Thnaks,