3 Replies Latest reply on Dec 28, 2006 3:17 AM by chris.huston.t10

    obtaining lastResult value

    Dr Khaled
      Hi all

      I have a java Remote Object (RM) which I send to it a data object and receive from it a string. The fist time the java RM activated, I receive just null string. The second time the java RM activated, I receive a value which I should have received from the first time I activated the java RM and so forth.

      Best regards

        • 1. Re: obtaining lastResult value
          chris.huston.t10 Level 3
          It sounds like you are making a synchronous call to your RemoteObject. You need set a result event to listen for the return value since the call to your RemoteObject is an asynchronous event. You set a listener function for the ResultEvent which will then be able to process the returned value properly. If you need help with this, post the code you are using for your RemoteObject call.

          Vygo
          • 2. Re: obtaining lastResult value
            Dr Khaled Level 1
            Thank you very much for your response.

            You are absolutely right about writing a listener. I have found that through searching the forum. But, no one says how? My program is little bit large. Therefore, I have written a small program which contains the necessary code. Please help me with writing the necessary listeners in the action script function that waits the response from the java remote object before executing the next commands. Please do not change the original program structure if possible. Thank you very much in advance. My program is as follows:

            <?xml version="1.0" encoding="utf-8"?>
            <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" layout="absolute">
            <mx:Script>
            <![CDATA[
            import mx.rpc.events.ResultEvent;
            import mx.events.MenuEvent;

            [Bindable]
            private var levelsA:Array = [0, 1, 2, 3, 4, 5];

            private function saveUpdateF():void {
            var result:String = roCourses.saveCourse(courseState.Text);

            if (roCourses.saveCourse.lastResult == "S")
            Alert.show("Data were saved.", "");
            else
            Alert.show("Data were not saved.", "");
            }
            ]]>
            </mx:Script>

            <mx:RemoteObject id="roCourses" destination="diCourses"/>

            <mx:Panel id = "mainPanel" x="10" y="10" width="516" height="550" layout="absolute">
            <mx:ComboBox x="20" y="30" width="66" id="courseState" dataProvider="{courseStatesA}"/>
            <mx:Button x="20" y="60" label="Save" id="saveUpdate" click = "saveUpdateF()" width="60"/>
            </mx:Panel>
            </mx:Application>
            • 3. Re: obtaining lastResult value
              chris.huston.t10 Level 3
              Here is how you can add a listener to your RemoteObject:

              private function saveUpdateF():void {
              var result:String = roCourses.saveCourse(courseState.Text);
              roCourses.addEventListener("result", saveStatus); //Set function to respond to result from RemoteObject.
              }

              private function saveStatus(evt:ResultEvent):void {
              var savedResult:String = evt.result as String; //Result type is object so needs to be cast as a string.
              if (savedResult == "S")
              Alert.show("Data were saved.", "");
              else
              Alert.show("Data were not saved.", "");
              }

              Vygo