Flash Remoting and Actionscript

The following code, according to the debug window, connects successfully and gets an array back from amfphp. However, the responder onResult does not load the array into the combobox. This code is a simplified form of coed in O'reilley's Flash Remoting: The Definitive Guide with a php "northwind" database. The amfphp service browser also works fine. Basically, the only thing in my flash movie is a combobox w/ the instance name of countries_cb... I added the last line at the end to make sure I could write a value/label pair to the combobox...and it works...so for some reason the responder is not getting invoked...The code is below.

Obviously I'm new and this should be simple...I just am not sure how to make sure actionscript is invoking the onResult responder...and I've searched until my heart's content...thanks in advance...

import mx.remoting.Service;

   import mx.rpc.RelayResponder;
   import mx.remoting.PendingCall;
   import mx.remoting.debug.NetDebug;
   import mx.services.Log;

//-------------------------------------------------------------------
// Define the URLs
//-------------------------------------------------------------------
gatewayURL = "http://dfwhomesales.com/flashservices/gateway.php";
serviceURL = "CustomersAdmin";

countryResponder = new Object( );
countryResponder.onResult = function (countries_rs) {
  var max = countries_rs.getLength( );

  countries_cb.setEnabled(true);
  countries_cb.addItem("All", 0);

  for (var i=0; i<max; ++i) {
    countries_cb.addItem(countries_rs.getItemAt(i).Country, i+1);
  }
  countries_cb.setSelectedIndex(0);

 
};

//-------------------------------------------------------------------
// Create the gateway and service objects
//-------------------------------------------------------------------

this.service = new Service(this.gatewayURL, new Log(), "CustomersAdmin", null, null);
service.getCountries(countryResponder);
countries_cb.addItem("All", 0);
chuckbeatsAsked:
Who is Participating?
 
Aneesh ChopraCommented:
Hi,

I have sent the fixed version back to your mail.
problem was that you were not catching the returned result in a object,
and after catching it in a object, you also need to parse it properly..

here is the updated code for others reference:
-------------
import mx.remoting.Service;
import mx.rpc.RelayResponder;
import mx.remoting.PendingCall;
import mx.remoting.debug.NetDebug;
import mx.services.Log;
//-------------------------------------------------------------------
// Define the URLs
//-------------------------------------------------------------------
gatewayURL = "http://dfwhomesales.com/flashservices/gateway.php";
serviceURL = "CustomersAdmin";
//
//-------------------------------------------------------------------
// Create the gateway and service objects
//-------------------------------------------------------------------
this.service = new Service(this.gatewayURL, new Log(), "CustomersAdmin", null, null);
myPendingCallObj = service.getCountries();
countries_cb.addItem("All", 0);
myPendingCallObj.onResult = function(result) {
      // catch the result and handle it for this application
      for (i=0; i<result._items.length; i++) {
            countries_cb.addItem(result._items[i].Country, i+1);
      }
      trace("-----------\ncombo populated\n-------------");
      /*for (i in result) {
            for (j in result[i]) {
                  trace(i+":"+j);
            }
      }*/
}
--------------

Rgds
Aneesh
0
 
chuckbeatsAuthor Commented:
Also, I'm not sure about the countries_cb.setEnabled(true);...so I have tried it w/out this line as well. If I remove the last line in the code..the "all" never gets put into the combobox from the responder function...so if there is a problem w. the array logic, I can deal with that when it comes...thanks
0
 
Aneesh ChopraCommented:
Hi,

seems like issue in the following code:
----------------
var max = countries_rs.getLength( );
--------------

if "countries_rs" is an array, then you should try this:
--------------
var max = countries_rs.length;
----------

Rgds
Aneesh
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

 
Aneesh ChopraCommented:
or,

you should first try tracing out to confirm that you are getting data in dataset object
----------
trace(countries_rs.getLength( ));
-----------
0
 
anjipCommented:
countryResponder.onResult = function(countries_rs)

where is countries_rs object

anji
0
 
chuckbeatsAuthor Commented:
Tried all this...still nothing...I have also tried for the OnResult function just to add a line to the combobox...

If I take ou the function () .. then a one line works like below...

countryResponder.onResult =countries_cb.addItem("I'm working!!", 1);

but if I try to add that to a function () is doesn't work...something is wrong with the code and the function definition.

I have determined the responder call is working...but still can't seem to get it to work invoking a function.
Anycode help would work...even if it doesn't have to do with the results...

How do I get a function constructed and working??
i.e.

countryResponder.onResult = function () {
countries_cb.additem("I'm working!!",1);
};

does not work...WHY?
0
 
Aneesh ChopraCommented:
try this:
----------
myfunction = function () {
    countries_cb.additem("I'm working!!",1);
    countries_cb.additem("still working!!",2);
};

//
countryResponder.onResult = myfunction;
-------------

Rgds
Aneesh

0
 
chuckbeatsAuthor Commented:
still nothing... :-(
0
 
Aneesh ChopraCommented:
are you using above code in a AS 2.0 class or on FLA frame....?
0
 
chuckbeatsAuthor Commented:
FLA frame.
0
 
Aneesh ChopraCommented:
can you provide the sample source files, it will help it to resolve it faster...

you may also send it to mail...  (mail is in profile)


I assure that i will provide the solution and provided source will be used only to provide assitance to your problem and will be deleted completely later on...

Rgds
Aneesh


0
 
chuckbeatsAuthor Commented:
Thank you...thank you...thank you...This is by far the best experts-exchange encounter I have ever had...BRAVO...I just wish I could give you higher than an A and about 50000000000000000 points!!!
0
 
Aneesh ChopraCommented:
you are welcome :)
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.