2 Replies Latest reply on Mar 14, 2008 10:18 PM by Sreenivas R

    XML Binding

      Hello, I'm quite new to Flex and I have this problem.
      I'd like to call an HTTPService that returns XML data in e4x format and assign the result to an AS3 class (LoginVO).
      But I get a message stating that I cannot assign the xml to the class at the following lines:
      LoginVO( event.result ) and LoginVO( event )
      Is it possible to do this? Should the xml written in some particular way? What else?
      Thanks in advance.
        • 1. Re: XML Binding
          Typically you have to have a constructor in your VO that takes the xml as a parameter. Then you assign each property in your constructor. Something like this . . .

          var myLoginVO = new LoginVO( event.result );
          In your constructor you would have something like this. . .
          public function Login( loginXMLList : XMLList ) : void
          this.userName = loginXMLList.item..userName;

          I'm not sure if you are getting xmllist back or xml etc. . .

          Also not sure what your LoginVO looks like but you should get the idea . ..
          • 2. Re: XML Binding
            Sreenivas R Adobe Employee
            I am unable to guess why you want the XML data to get converted to e4x format and then to LoginVO Object.

            HTTPService by default would convert XML data to Objects. But they won't be of LoginVO type or anyother type. They would be palin objects.
            You can have a constructor / creator function in LoginVO which accepts a Object and creates a new LoginVO object using the properties/values in the object.

            public function createLoginVO(obj:Object):LoginVO
            var loginVO:LoginVO = new LoginVO();
            for (var prop:String in obj)
            loginVO[prop] = obj[prop];
            return loginVO;

            Above code assumes that LoginVO has same properties as the XML data returned. You can add checks or hard coded values in the function.

            Call this function from the HTTPService handler.