views:

19

answers:

0

All I got "Cannot perform operation on a NativeProcess that is not running." when running debug mode in Flex 4 Builder. Where should I place my HelloWorld.class in IDE project folder?

<?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/halo"
                       applicationComplete="windowedapplication1_applicationCompleteHandler(event)"
                       close="windowedapplication1_closeHandler(event)"
                       showStatusBar="false" viewSourceURL="srcview/index.html">
    <fx:Script>
        <![CDATA[
            import flash.events.Event;
            import flash.events.MouseEvent;
            import flash.events.ProgressEvent;
            import flash.utils.ByteArray;

            import mx.events.FlexEvent;

            private var nativeProcess:NativeProcess;
            private var npInfo:NativeProcessStartupInfo;
            private var processBuffer:ByteArray;
            private var bLength:int = 0;

            protected function windowedapplication1_applicationCompleteHandler(event:FlexEvent):void
            {
                var arg:Vector.<String> = new Vector.<String>;
                arg.push("HelloWorld");

                processBuffer = new ByteArray;

                npInfo = new NativeProcessStartupInfo;
                npInfo.executable = new File("C:/Program Files/Java/jdk1.6.0_22/bin/java.exe");
                npInfo.arguments = arg;

                trace(npInfo.executable);

                nativeProcess = new NativeProcess;
                nativeProcess.addEventListener(ProgressEvent.STANDARD_OUTPUT_DATA, onStandardOutputData);
                nativeProcess.start(npInfo);
            }

            private function onStandardOutputData(e:ProgressEvent):void
            {
                tArea.text += nativeProcess.standardOutput.readUTFBytes(nativeProcess.standardOutput.bytesAvailable);
            }


            protected function button1_clickHandler(event:MouseEvent):void
            {
                tArea.text += 'AIR app: '+tInput.text + '\n';
                nativeProcess.standardInput.writeMultiByte(tInput.text + "\n", 'utf-8');
                tInput.text = '';
            }


            protected function windowedapplication1_closeHandler(event:Event):void
            {
                nativeProcess.closeInput();
            }

        ]]>
    </fx:Script>
    <s:Button label="Send" x="221" y="11" click="button1_clickHandler(event)"/>
    <s:TextInput id="tInput" x="10" y="10" width="203"/>
    <s:TextArea id="tArea" x="10" width="282" height="88" top="40"/>
</s:WindowedApplication>