Friday, May 10, 2002

Flash Remoting and Web Services : Retrieving Stock Quote Information

This is a simple Flash example that calls a Stock quote web service via Flash Remoting. You can find more info on the web service being used below at xmethods.net.

1. Download and install the ColdFusion MX preview release.

2. Download and install the Flash Remoting add-ons for Flash MX.

3. Create a new Flash movie and enter the the following code in the first frame of the movie.

#include "NetServices.as"
var params = new Object();
//this is always 0, and is specific to the web service.
params.LicenseKey = "0";
//stock symbol we want information about
params.StockSymbol = "macr";
//create an object to catch the response from the web service
var result = new Object();
//data is an object which contains properties with information about the stock.
result.onResult = function(data)
{
 //loop through all of the properties and print them out
 for(var x in data)
 {
  trace(x + " : " + data[x]);
 }
}
 
//this gets called if an error occurs.
result.onStatus = function(error)
{
 //print out the error
 trace("Error : " + error.description);
}
//the path to the web service's WSDL file.
var webServiceWSDL = "http://ws.cdyne.com/delayedstockquote/delayedstockquote.asmx?wsdl";
var gw = NetServices.createGatewayConnection("http://localhost:8500/flashservices/gateway/");
var service = gw.GetService(webServiceWSDL, result);
//call a method on the web service, passing params.
service.GetQuote(params);
Test the movie. You should see the data from the web service print in the Output window. 
5:20:10 PM    comment []  Google It!  

Finding more info on the CF object in ServerSide ActionScript

Joey Lott sent the following information to me.

When using ServerSide ActionScript there is an object available called CF with includes methods to make database queries and http requests. However, it also contains a number of other properties and methods which are undocumented, but could prove to be useful. Remember though, use undocumented features at your own risk as they may be changed or removed in future versions of the product.

Below is some code that shows how to find all of the properties and methods of the CF object on the server.

First create a file called Names.asr in the <cfinstall>/wwwroot/com/test directory and add the following code:

function getCF()
{
 var cfStuff = "";
 for(i in CF)
 {
  cfStuff += i + "\n";
 }
 return cfStuff;
}

Next, create a new Flash movie and add the following code:

#include "NetServices.as"
var o = new Object();
o.onResult = function(data)
{
 trace(data);
}
var gwURL = "http://localhost:8500/flashservices/gateway";
var gw = NetServices.createGatewayConnection(gwURL);
var names = gw.getService("com.test.Names", this);
names.getCF();

Test your movie, and you should see the following output in your Output window:

removeAttribute
include
getSession
servletContext
page
setAttribute
request
response
toString
initialize
wait
getClass
exception
http
hashCode
popBody
getAttributeNamesInScope
pushBody
getException
class
notify
getRequest
getAttributesScope
release
equals
getPage
getOut
session
getAttribute
getServletConfig
forward
servletConfig
out
findAttribute
notifyAll
handlePageException
getServletContext
query
getResponse

Pretty cool, heh? If you find some good uses for some of the properties, post them in the comments. Thanks again to Joey Lott who figured this out.

11:30:10 AM    comment []  Google It!  

© Copyright 2003 Mike Chambers.
 
May 2002
Sun Mon Tue Wed Thu Fri Sat
      1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31  
Apr   Jun


Macromedia MX

Resources

Flash MX

Aggregators

Books

Click here to visit the Radio UserLand website.

Subscribe to "Examples" in Radio UserLand.

Click to see the XML version of this web page.

Click here to send an email to the editor of this weblog.