Tuesday, May 07, 2002

Creating a Proxy for Flash using Flash Remoting and ServerSide ActionScript

This is a simple example that shows how to make a proxy using Flash Remoting and ServerSide ActionScript. The proxy will allow you to load XML and other data into Flash from domains other that the one the Flash movie was loaded from.

1. Download and install the ColdFusion MX preview release.

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

Create a file called Proxy.asr in the:

<cfhome>/wwwroot/com/macromedia/proxy

directory.

Add the following code the Proxy.asr file

function getURL(url)
{
 var stream = CF.http(url).get("Filecontent");
 return stream;
}

This takes a URL as a parameter and retrieves it using CF.http(). The remote data is retrieved by calling get("Filecontent") and stored in a variable named stream. The variable and its data is then returned to the Flash movie.

Next, open Flash, and add the following code to the first frame of the movie:

#include "NetServices.as"
#include "NetDebug.as"
Result = function(){};
Result.prototype.onResult = function(data)
{
 trace("Data : " + data);
}
Result.prototype.onStatus = function(error)
{
 trace("Error : " + error.description);
}
var remoteURL = "http://www.macromedia.com/desdev/resources/macromedia_resources.xml";
var gw = NetServices.createGatewayConnection("http://localhost:8500/flashservices/gateway");
var proxy = gw.getService("com.macromedia.proxy.Proxy", new Result());
proxy.getURL(remoteURL);

Test the Flash movie in the authoring environment. You should see the Macromedia XML Resource feed printed out in the debug window. If an error occurs, a description should be printed in the Debug window (or you can check the NetConnection Debugger Window > NetConnection Debugger).


 

10:18:57 PM    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.