3 Replies Latest reply on Jun 20, 2009 9:18 PM by SunilAdobe

    How to reference a cfc cfreturn string in actionscript without mx:remoteobject

    cebdev

      The coldfusion form generation wizard works great!!! But, it creates the binding elements quite differently than I am used to.  I love the way it polls the cfc to gather the call information.  The cfcs that return a query and bind them to a control work fine.  All this appears to be done without using mx:remoteobject.

       

      But, I have a button that calls a function that calls a cfc with the goal of returning a simple string element.  I don't know how to access it in actionscript without using mx:remoteobject.

       

      So I have this CFC:

      <cfcomponent>

      <cffunction name="addValidation" access="remote" returntype="string">
        <cfset addLine = "insert into validation (tableName,fieldName,fieldValue,sortOrder,fieldDesc) VALUES ('ALL','ALL','NONE',0,'NEW record');">
        <cfquery name="updValidation" datasource="#dbds#" username="#dbli#" password="#dbpw#">
         #preserveSingleQuotes(addLine)#
        </cfquery>
        <cfset getLatest = "select top 1 validationID from validation order by validationID desc">
        <cfquery name="lastID" datasource="#dbds#" username="#dbli#" password="#dbpw#">
         #preserveSingleQuotes(getLatest)#
        </cfquery>
        <cfset latest = #getLatest.validationID#>
        <cfreturn #latest#>
      </cffunction>
      </cfcomponent>

       

      This cfc functions properly when called and adds the new record.  It is also supposed to return the new record key.

       

      This cfc is called in this function:

       

       

       

       

       

       

       

      protected function AddNew_clickHandler(event:MouseEvent):

      void

      {

      addValidation.token = validationFunctions.addValidation();

      getGridResult.token = validationFunctions.getGrid(

      "ALL","ALL");

      Alert.show(

      "New record " + addValidation.lastResult.show() + " added, edit below to add field contents"

      );

       

       

       

       

      }

       

      The function does correctly call the addValidation routine and the getGrid routine refreshes the data grid.  The alert errors out.  I don't know how to reference the cfc string result outside the context of a remoteobject.

       

      What is the syntax???

       

      Craig

        • 1. Re: How to reference a cfc cfreturn string in actionscript without mx:remoteobject
          SunilAdobe Adobe Employee

          The functions called in a CFC, as part of RemoteObject are asynchronous and they do not return immediately, hence a token is returned. The right way to do this as is  (I guess addValidation is of type callResponder and its result event handler is not mapped in the code given by you)

           

          addValidation.token = validationFunctions.addValidation();

          addValidation.addEventListener(ResultEvent.RESULT,resultHandler);

          private function resultHandler(event:ResultEvent)
          {

          Alert.show("New record " + addValidation.lastResult.show() + " added, edit below to add field contents");

          }

           

          Hope this helps.

          -Sunil

          • 2. Re: How to reference a cfc cfreturn string in actionscript without mx:remoteobject
            cebdev Level 1

            Sunil,

             

            you got me 95% there.? The thing that finally compiled and returned the record key was this:

             

             

             

            protected function AddNew_clickHandler(event:MouseEvent):void

            protected function AddNew_clickHandler(event:MouseEvent):void

            {

             

            addValidation.token = validationFunctions.addValidation();

             

            addValidation.addEventListener(ResultEvent.RESULT,resultHandler);

             

            }

             

             

             

            private function resultHandler(event:ResultEvent)

            {

             

             

             

            Alert.show("New record " + addValidation.lastResult + " added, edit below to add field contents");

            }

             

             

            private function resultHandler(event:ResultEvent)

            {

             

             

             

            Alert.show("New record " + addValidation.lastResult + " added, edit below to add field contents");

            }

             

            "New record " + addValidation.lastResult + " added, edit below to add field contents");

            }

             

             

            I'm still a bit new to this and don''t understand the architecture clearly enough to know when I need to code whatever event handler.

             

            Thanks for your help.? You got me over the hump.

             

            Craig

            • 3. Re: How to reference a cfc cfreturn string in actionscript without mx:remoteobject
              SunilAdobe Adobe Employee

              cebdev, Did you try to look in the help->start page or the videos to understand more about the architecture on how to connect to services?

              Let us know if they are of help and anything there needs attention.