5 Replies Latest reply on Jul 6, 2007 2:44 PM by Newsgroup_User

    Unable to assign VO.

    Level 7
      What basic concept am I missing here?

      import Model.troubleLogVO;
      ...
      [Bindable]
      public var troubleLogEntry:troubleLogVO = new troubleLogVO;
      ...
      /* CRUD readEvent result Handler */
      protected function readEventResult(e:ResultEvent):void
      {
      troubleLogEntry = e.result as troubleLogVO;
      Alert.show(e.result.id);
      Alert.show(troubleLogEntry.id);
      }


      The first Alert works, e.result.id shows the proper value. The second
      Alert fails saying that one can not access properties on a Null object.

      TIA
      Ian
        • 1. Re: Unable to assign VO.
          ntsiii Level 3
          Is troubleLogEntry getting set correctly? Can you access the troubleLogVO properties, say from a button?

          I still mistrust your assignment and think you should do it in an init function.

          Tracy
          • 2. Re: Unable to assign VO.
            Level 7
            I believe so, adding the following line to the mxml file seems to work
            correctly.

            <mx:Text id="test" text="{troubleLogEntry.id}"/>

            This displays a default string I put into the id property in the
            troubleLogVO.as file.

            But it still throws a "Null" error after I try to assign the data
            returned from a RemoteObject call to my back end CFC.




            ntsiii wrote:
            > Is troubleLogEntry getting set correctly? Can you access the troubleLogVO properties, say from a button?
            >
            > I still mistrust your assignment and think you should do it in an init function.
            >
            > Tracy
            • 3. Re: Unable to assign VO.
              ntsiii Level 3
              Ah, I have doubt this will work:
              troubleLogEntry = e.result as troubleLogVO;

              It will require that the result object contain an instance of troubleLogVO, wich is not realy possible because result is either xml, Object, or text.

              Tracy
              • 4. Re: Unable to assign VO.
                Level 7
                Then what is the proper way to call a CFC with remoteObject and set it
                to a custom value object?

                I'm working off of examples such as this one.

                http://www.brucephillips.name/blog/index.cfm/2007/3/16/Developing-A-Login-System-For-A-Fle x-Application-With-A-ColdFusion-and-Database-Backend-Part-1

                <?xml version="1.0" encoding="utf-8"?>
                <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml"
                layout="absolute" creationComplete="initVars()"
                viewSourceURL="srcview/index.html">

                <mx:Script>
                <![CDATA[

                import mx.rpc.events.ResultEvent;
                import mx.rpc.events.FaultEvent;
                import mx.utils.ObjectUtil;
                import mx.controls.Alert;
                import mx.collections.ArrayCollection ;


                [Bindable]
                private var aMember:Member;

                //called automatically when app is first run private function
                initVars():void {

                /*
                Test method when sending a username and password
                that exists in the database
                should cause resultGetMemberByUserNameAndPassword
                function to be called
                */
                MemberService.getMemberByUserNameAndPassword('phil1021','seven');

                /*test method when sending username and password that don't exist
                should cause the faultGetMemberByUserNameAndPassword function
                to be called*/
                MemberService.getMemberByUserNameAndPassword('test','testPassword');

                } //end function initVars()

                /*Called automatically when the result is returned by the
                CFC method getMemberByUserNameAndPassword
                */
                public function
                resultGetMemberByUserNameAndPassword(event:ResultEvent):void {

                //used for debugging - shows details about result //returned by the CFC
                method Alert.show( ObjectUtil.toString(event.result) );


                /*result returned is a Member object
                cast the result returned to a Member class
                and assign it to our Member object*/
                aMember = event.result as Member ;

                /*example of how to access the values of the aMember
                object */
                Alert.show("Member ID: " + aMember.memberID +
                "\nPassword: " + aMember.password +
                "\nFirst name: " + aMember.firstName +
                "\nLast name: " + aMember.lastName +
                "\nEmail: " + aMember.email );


                } //end function getMemberByUserNameAndPassword

                /*
                automatically called if the CFC method call causes an error
                */
                private function
                faultGetMemberByUserNameAndPassword(event:FaultEvent):void{

                Alert.show( ObjectUtil.toString(event.fault) );


                }//end function faultGetMemberByUserNameAndPassword

                ]]>
                </mx:Script>


                <!--setup the connection to the ColdFusion CFC
                NOTE: path for the source will depend on
                where you placed the MemberService.cfc-->
                <mx:RemoteObject
                id="MemberService"
                destination="ColdFusion"
                source="brucephillips.GeekNews.MemberService"
                showBusyCursor="true"
                >
                <mx:method name="getMemberByUserNameAndPassword"
                result="resultGetMemberByUserNameAndPassword(event)"
                fault="faultGetMemberByUserNameAndPassword(event)"/>

                </mx:RemoteObject>

                </mx:Application>


                ntsiii wrote:
                > Ah, I have doubt this will work:
                > troubleLogEntry = e.result as troubleLogVO;
                >
                > It will require that the result object contain an instance of troubleLogVO,
                > wich is not realy possible because result is either xml, Object, or text.
                >
                > Tracy
                >
                • 5. Re: Unable to assign VO.
                  Level 7
                  Working on this theory and with much trial and error, I found my problem!

                  The Flex Builder CFC -> AS Wizard was not putting the full path to the
                  CFC in the alias! I added the "Model" directory and it started working.
                  Bad wizard, bad wizard!

                  This ActionScript Value Object now works properly.
                  package Model
                  {
                  [RemoteClass(alias="Model.troubleLogVO")]

                  [Bindable]
                  public class troubleLogVO
                  {

                  public var ID:String = "Default";
                  public var APPLICATION:String = "Default";


                  public function troubleLogVO()
                  {
                  }

                  }
                  }

                  One just has to love these specific little gotcha's when one is learning
                  something new and does not really know what is what , where any of it
                  goes and how it all works together.

                  João_Fernandes wrote:
                  > Ian, for some reason your mappings between the as3 class and your cfc
                  aren't working
                  >
                  > you should have something like
                  >
                  > (test.TroubleLog)#0
                  > application = "testing"
                  > id = "9CDFE043-19D1-2F3E-AAD0BBD311D248B9"
                  >
                  > Are you returning a troubleLog CFC instance from that call?
                  >
                  > João Fernandes