8 Replies Latest reply on Jun 25, 2010 9:45 AM by rashmin.d

    Binding event.result to object returns null

    CF_WebHed
      Hi,

      I'm trying to Bind the results of an event to an object, which is then used as the source for a form. This is the code I'm using:

      private function get_result(event:ResultEvent):void
      {
      var detail:StafftblUser = event.result as StafftblUser;
      Alert.show(ObjectUtil.toString(detail));
      //originaltblUser_TitleID = detail.TitleID;
      //originaltblUser_UserTypeID = detail.UserTypeID;

      this.detailObject = detail;
      }

      But from this the object 'detail' is always null. When I output the event.result in an Alert I can see all the results returned, but when I output the object detail its null.

      Not sure why.

      Stephen
        • 1. Re: Binding event.result to object returns null
          peterent Level 2
          When binding use: {event.lastResult} and not event.result.
          • 2. Re: Binding event.result to object returns null
            CF_WebHed Level 1
            Um, not sure if I'm using this right, this is my code:
            private function get_result(event:ResultEvent):void
            {
            var detail:StafftblUser = event.lastResult as StafftblUser;
            Alert.show(ObjectUtil.toString(event.lastResult));
            this.detailObject = detail;
            }
            But Flex builder is telling me that

            'Access of possibly undefined property lastResult through a reference with static type mx.rpc.events:ResultEvent.'

            Do results from events come back as an Array and can you control the type results come back as?
            • 3. Re: Binding event.result to object returns null
              ntsiii Level 3
              Your topic title is wrong.

              In your example, you are not "binding", you are assigning the value directly, so you should NOT use the lastResult, but should use result as in your example.

              Are you passing event to the handler in the declaration:
              result="get_result(event)"

              How are you examining detail?

              Tracy
              • 4. Re: Binding event.result to object returns null
                ntsiii Level 3
                Ignore my last question, I see you are using alert.
                • 5. Re: Binding event.result to object returns null
                  ntsiii Level 3
                  Ahh ignore most of my post, I didn't read closely enough before responding.

                  For this to work:
                  var detail:StafftblUser = event.result as StafftblUser;

                  the result object must contain an instance of StafftblUser. This seems kind of unlikely unless you are using RemoteObject and have registered VOs, and all of that is working correctly.

                  Tracy
                  • 6. Re: Binding event.result to object returns null
                    CF_WebHed Level 1
                    Hi,

                    I did finally manage to get this working, by assigning values using this syntax:

                    this.detailObject.Firstname = event.result.firstname;

                    This works fine, but in ActionScript can you create argument constructors to pass the event.result object into to assign the values in the ActionScript object?
                    • 7. Re: Binding event.result to object returns null
                      EvolvedDSM Level 2

                      I'm going through this myself.

                       

                      I've actually got a regestered VO and I still couldn't get it to work.

                       

                      employee:tagoutUser = new tagoutUser();

                       

                      then in my result function...

                      employee = event.result as tagoutUser;

                       

                      This didn't work for me.  When I debug, my variables tab shows that event.result is being passed as valueObjects.tagoutUser, but it's still not matching up correctly.

                       

                      What is working though is...

                      employee = event.result[0];

                       

                      because my result is actually an array of my remoteObject call.  So getting the only record [0] in the array assigns to my VO properly.

                       

                      I still don't understand why employee = event.result as tagoutUser doesn't work, but I'm guessing it's because event.result is an array and it doesn't know which object in the array to pass to the VO.

                       

                      Also, another thing that works is...

                       

                      employee = (event.result as Array)[0] as tagoutUser

                       

                      So, for your example, you may want to try one of these solutions:

                      detail:StafftblUser = new StafftblUser();

                      detail = event.result[0]; OR detail = (event.result as Array)[0] as StafftblUser;

                       

                      Let me know if this helps you.

                       

                      edit: corrected my last example to use StafftblUser.

                      • 8. Re: Binding event.result to object returns null
                        rashmin.d

                        hi...CF_WebHed

                         

                        i seen your que...... i think u solved first one... so, i will tell u abt your 2nd que...YES u can create argument constructor n pass the object...

                         

                        i think u create a Model to store that data.. sending n receiving data from that model..... So it's custom VO so first try to relate u have to connect Flex VO class to server side VO class....by puting this tag into the flex VO class [RemoteClass(alias="Dir.Class")] so when u set Remote Service n call particular function on server n in ResultEvent try get VO object from the result u can convert it to your Flex VO object... n u have to consider same thing for server VO class ... n second important thing is mapping of Data Type btw Flex VO class n Server VO class...

                         

                        Consider this two things it should work......

                         

                        it may help u....