Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / Flash / Flash Remoting / January 2006



Tip: Looking for answers? Try searching our database.

Multiple function calls in AS2

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Rockabill - 25 Jan 2006 17:24 GMT
Hi there, I'm hoping some kind soul can help me solve this problem which has me
baffled.
I'm using AS 2 remoting and CF 6.1 and I'm new to remoting but familiar with
Coldfusion.

I can successfully populate a dropdown box for selecting a country via
remoting binding the data to the combobox using the first function.
 I am using the combobox data to query the cfc again for a filtered recordset
using (countryid) as the argument (simple enough).
Two functions, 2 pending calls and 2 result events.
My problem is although I can see the recordset returned (filtered by the
argument)  I can't get this data into the  second Result event.
I'm using the Netdebugger tool and can see the correct returned recordset. No
errors.
Using trace and hardcoding a value as an argument works within the second
function but only if the first function is disabled.!!

Within the second pending call I am using the following code

(Using the value returned from the first function )
var pc: PendingCall  = myService.ListByDepts(depts_cb.selectedItem.data);
The responder is
pc.responder = new RelayResponder(this, "ListByDept", "ListByDept_Fault");

The result event function is
function ListByDept( re:ResultEvent):Void {
trace("inside the second function")
}
nicetim - 28 Jan 2006 03:43 GMT
Hi Rock,
 i am also new, but thought i would share with you what works for me in the
same configuration. I am not sure this code woud quallify as AS2 though.
I hope it helps solve your problem.

form with 2 combo boxes ComboBox1, ComboBox2
no other components, but make sure you have the Remoting classes in your
Library.

i setup simple CFC functions the just query a table for two fields and return
the query results. make the cffunction tag "remoting" and the datatype return
"Query"

in flash 8 i import the remoting classes like so:

import mx.remoting.*;
import mx.remoting.debug.*;

//then my connections:
NetServices.setDefaultGatewayUrl(conStr);
connection = NetServices.createGatewayConnection();

//setup each service here if you need more than 1 just make as many as you
need for different CFC's

Service = connection.getService("CFC", this);
var paramList = firstQueryParamValue;

//then trigger your methods:
Service.CFCmethodName1(paramList);

//setup function to handle results of first service call and to populate the
//comboBoxs

function CFCmethodName1_Result(result) {
// .. your code that fires when a result has returned
// assign dataProvider
ComboBox1.dataProvider = result;
//then trigger your second method here.
Service.CFCmethodName2(ComboBox1.selectedTarget.data);

}
function CFCmethodName1_Status(result) {
// .. your code that fires when a fault happens
}

function CFCmethodName2_Result(result) {
// .. your code that fires when a result has returned
// assign dataProvider
ComboBox2.dataProvider = result;
}
function CFCmethodName2_Status(result) {
// .. your code that fires when a fault happens
}

it would be better to create two objects first and  assign those to the
dataProvider of the combo boxes. then in your result functions just assign
those objects the "result" object.
Also, make sure before you are removing all items first then call the service.

regards

tim
Rockabill - 31 Jan 2006 15:22 GMT
Hi Tim,

Thanks for the reply and example, I had already managed to get it working and
here's the code, might help someone else :)
I had found my answer in
Macromedia? Flash? Professional 8 UNLEASHED
By David Vogeleer, Eddie Wilson, Lou Barber
...............................................
Publisher: Sams
Pub Date: October 12, 2005
ISBN: 0-672-32761-9

I hope to build on this experience over time as I think Remoting is pretty
cool stuff.
   
Basically just  a combo and List boxes passing argument from combo to populate
the list box.

*******************************
<!--- Use for testing if you can connect remotely --->
<CFFUNCTION NAME="getTestConn" HINT="Get a test connection" ACCESS="remote"
RETURNTYPE="string">

    <CFRETURN ".....connection sucessful">

</CFFUNCTION>

<CFFUNCTION NAME="ListDepts" HINT="Get a List  of departments" ACCESS="remote"
RETURNTYPE="query">
    <CFQUERY DATASOURCE="exampleapps" NAME="dept">
        SELECT * FROM tblDepartments
        ORDER BY DepartmentName
    </CFQUERY>

    <CFRETURN dept>
</CFFUNCTION>

<!--- Obtain department employees --->
<CFFUNCTION NAME="ListByDept" HINT="Get employees based on department"
ACCESS="remote" RETURNTYPE="query">
<CFARGUMENT NAME="DepartmentID" TYPE="string" REQUIRED="yes">
    <CFQUERY DATASOURCE="exampleapps" NAME="emps">
        SELECT * FROM tblEmployees
        WHERE DeptIDFK = '#ARGUMENTS.DepartmentID#'
        ORDER BY LastName, FirstName
    </CFQUERY>

    <CFRETURN emps>
</CFFUNCTION>

*******************************
// Import the Flash Remoting Classes
import mx.remoting.Service;
import mx.services.Log;
import mx.remoting.PendingCall;
import mx.remoting.RecordSet;
import mx.rpc.RelayResponder;
import mx.rpc.ResultEvent;
import mx.rpc.FaultEvent;
import mx.remoting.DataGlue;
//Connect to the gateway
var myService:Service = new Service(  
  "http://localhost/flashservices/gateway",
  new Log(Log,DEBUG),
  "cfflash1.employee",
  null,
null );

// Test the connection
function getTestConn() {
    // create a Pending Call object
    var testConn_pc:PendingCall = myService.getTestConn();
    //Use the responder property to handle success or failure
    testConn_pc.responder = new
RelayResponder(this,"getTestConn_Result","getTestConn_Fault");
}
// Handle the success
function getTestConn_Result(re:ResultEvent){
    //trace(re.result);
    pageTitle.text = re.result;
    //Call the listDepts function to start the application
    listDepts();
}
// Handle a failure
function getTestConn_Fault(re:FaultEvent){
    trace(" An error has occurred");
}

// get the countries
function listDepts(){
    // call service function
    var departments_pc:PendingCall = myService.listDepts();
    departments_pc.responder = new
RelayResponder(this,"listDepts_Result","listDepts_Fault");
}
function listDepts_Result(re:ResultEvent){
    trace("Got Depts - " + re.result.length + " Records" );
    // display successful result in the combo box
 
    DataGlue.bindFormatStrings(depts_cb,re.result,"#DepartmentName#","#DepartmentID
#");
   
}
function listDepts_Fault (fe:FaultEvent):Void {
  trace("DeptsCallFailed-");
}
//get the employees for the selected dept
 function listByDept(departmentId){
    var employeesDetails_pc:PendingCall = myService.listByDept(departmentId);
    employeesDetails_pc.responder = new
RelayResponder(this,"listByDept_Result","listByDept_Fault");
 }

function listByDept_Result (re:ResultEvent)
{
    //trace("Got employees - " + re.result.length + " Records" );
    // display successful result in the list box
      DataGlue.bindFormatStrings(employees_lb,re.result,"#LastName","#LastName#");
     
}       

function listByDept_Fault (re:FaultEvent) {
    trace("Got an error");
}   
           
// create an event handler for the dropdown box
    var onDeptChangeListener :Object = new Object();
    this.onDeptChangeListener.change = function()
    {
        var departmentId:String = depts_cb.selectedItem.data;
        listByDept(departmentId);
    }
    this.depts_cb.addEventListener("change", onDeptChangeListener);
       
// Start the application
getTestConn();
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.