?
Solved

Flash Remoting and Actionscript

Posted on 2006-05-21
13
Medium Priority
?
362 Views
Last Modified: 2008-02-01
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);
0
Comment
Question by:chuckbeats
  • 7
  • 5
13 Comments
 

Author Comment

by:chuckbeats
ID: 16729217
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
 
LVL 34

Expert Comment

by:Aneesh Chopra
ID: 16731314
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
 
LVL 34

Expert Comment

by:Aneesh Chopra
ID: 16731327
or,

you should first try tracing out to confirm that you are getting data in dataset object
----------
trace(countries_rs.getLength( ));
-----------
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 1

Expert Comment

by:anjip
ID: 16733565
countryResponder.onResult = function(countries_rs)

where is countries_rs object

anji
0
 

Author Comment

by:chuckbeats
ID: 16735251
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
 
LVL 34

Expert Comment

by:Aneesh Chopra
ID: 16735501
try this:
----------
myfunction = function () {
    countries_cb.additem("I'm working!!",1);
    countries_cb.additem("still working!!",2);
};

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

Rgds
Aneesh

0
 

Author Comment

by:chuckbeats
ID: 16739326
still nothing... :-(
0
 
LVL 34

Expert Comment

by:Aneesh Chopra
ID: 16739348
are you using above code in a AS 2.0 class or on FLA frame....?
0
 

Author Comment

by:chuckbeats
ID: 16739678
FLA frame.
0
 
LVL 34

Expert Comment

by:Aneesh Chopra
ID: 16739689
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
 
LVL 34

Accepted Solution

by:
Aneesh Chopra earned 2000 total points
ID: 16739937
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
 

Author Comment

by:chuckbeats
ID: 16740098
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
 
LVL 34

Expert Comment

by:Aneesh Chopra
ID: 16740163
you are welcome :)
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This is a very simple example to help those of you who are still migrating from AS2 to AS3 understand the redesigned event model in AS3. In AS2.0, event functions (that is, the function to be performed when an event is fired) were stored as a pro…
I know the transition can be hard. We got used to the ease of use ActionScript 2 had, but honestly, it became problematic later on, especially if designers were involved in the project and found it easy to add code as they saw fit. So, this artic…
In this tutorial viewers will learn how to create a basic shape tween animation in Flash including shape hints for smooth animation Open a new document in Flash: Draw a shape: Select another frame (how long you want the tween to be): Right click and…
The goal of the tutorial is to teach the user how to how to load their YouTube profile onto Flash Media Live Encoder.

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question