Flash Remoting.com
Home Book Examples Blog Resources About
Search

You are using an out-of-date browser so the pages will not display properly. Please update your browser.

Random thoughts on Flash Remoting:

This is where I get to ramble when I feel like it. Kind of like a blog, but it's not a blog. This is a blog. ;-).

98 posts.

1/06 | 9/05 | 8/05 | 7/05 | 10/04 | 8/04 | 7/04 | 6/04 | 4/04 | 3/04 | 2/04 | 1/04 | 12/03 | 11/03 | 10/03 | 9/03 | 8/03 | 7/03 | 6/03 | 5/03 | 4/03 | 3/03 | 1/03 | 12/02 | 11/02

Hacking an Include for ServerSide ActionScript

Sunday, December 08, 2002 12:33:12 AM

I've been looking at ServerSide ActionScript lately just to see what is possible and if it's worthwhile using as an alternative to CF in some situations. One of the problems of SSAS is the inability to include files. SSAS files in Flash Remoting are simply repositories for remote methods. You can't include other SSAS files, or write inline code. Purely as an exercise I was fiddling with some Java and trying to come up with a way to include another file in a SSAS file. I was able to hack an include function, but it's not very usable. Hopefully Macromedia will include the include functionality in the next iteration of Flash Remoting and ServerSide ActionScript.

Anyway, a simple object in SSAS (saved as "testInclude.asr"):


function TestObject(myVar) {
   this.test = myVar
}

TestObject.prototype.getTest = function() {
   return this.test;
}

And another simple .asr file named testMyInclude.asr to invoke the object by use of a hacked include function:

function include(filename) {
  var fStream = new java.io.FileInputStream(filename);
  var inStream = new java.io.DataInputStream(fStream);
  var fileContent = "";
  while (inStream.available() !=0){
    // Add lines to the string from the stream
    fileContent += inStream.readLine();
  }
  inStream.close();
  return(fileContent);
}

// This is the remote method that will be called by Flash Remoting.
// it uses an include file referenced with the full file path, and evaluated
// with eval. I've only tried this technique with very
// simple files.


function testInclude(param) {
  try{
    eval(include("c:/cfusionmx/wwwroot/myFolder/testInclude.asr"));
  }catch(e){
     throw("Error in include:" + e);
  }
  // Create a new object from the include file
  var myTest = new TestObject(param);
  // Execute a method of the new object
  return myTest.getTest();
}

And finally, the ActionScript to invoke the remote method testInclude():

#include "NetServices.as"

var myURL = "http://localhost:8500/flashservices/gateway";
var servicePath = "myFolder.testMyInclude";
if(!initialized) {
  initialized = true;
  NetServices.setDefaultGatewayUrl(myURL);
  var my_conn = NetServices.createGatewayConnection();
  var myService = my_conn.getService(servicePath);
}
// responder object to display the result or error
function MyResponder() {
  this.onResult = function(myResult) { trace(myResult); },
  this.onStatus = function(myStatus) { trace("Error: "+ myStatus.description); }
}
System.onStatus = function(myStatus) {trace(mystatus.description)};


// invoke the remote method. Whatever is passed will be echoed back


myService.testInclude(new MyResponder(), "SSAS is cool");

This also demonstrates try/catch inside of a ServerSide ActionScript method. The try/catch construct should be used in all SSAS methods to trap any possible errors.

Add comment (3)
View comments

Using Regular Expressions in ServerSide ActionScript

Thursday, December 05, 2002 4:51:52 PM

One of the coolest things about ServerSide ActionScript is that it has the full capabilities of ECMAScript, including the RegExp object. Here is a simple demo with a bit of code that you can place in a file called RegExpTest.asr on your ColdFusion MX (or JRun 4) server that has two simple remote methods: isValidEmail() and stripHTML():

// ServerSide ActionScript file RegExpTest.asr

function stripHTML(theString){
  var theExpression = new RegExp("<[^>]*>","g");
  return theString.replace(theExpression,"");
}


function isValidEmail(theString) {
  var theExpression = /^[A-Za-z0-9\_\-]+\@[A-Za-z0-9\_\-]+.*\.\w{2,6}$/
  return theExpression.test(theString);
}

Some simple Flash Remoting code will call the remote methods and trace the result to the output window:

#include "NetServices.as"

//Set the myURL and servicePath variables to
// your own Flash Remoting path and service path

var myURL = "http://192.168.0.15:8100/cfmx/flashservices/gateway";
var servicePath = "myFolder.RegExpTest";


if(!initialized) {
  initialized = true;
  NetServices.setDefaultGatewayUrl(myURL);
  var my_conn = NetServices.createGatewayConnection();
  var myService = my_conn.getService(servicePath);
}


// responder object to display the result or error
function MyResponder() {

  this.onResult = function(myResult) {
    trace(myResult);
  }

  this.onStatus = function(myStatus) {
    trace("Error: "+ myStatus.description);
  }
}


myService.stripHTML(new MyResponder(),
   "<html><body>Hello! This is a <b>TEST</b></body></html>");


myService.isValidEmail(new MyResponder(),
  "jimjehosephat@thejehosephatlodge.com");

After running this, you should see the following in the Trace window:

Hello! This is a TEST
true

More info on regular expressions here:

http://developer.netscape.com/docs/manuals/js/client/jsguide/regexp.htm

Add comment (0)
View comments

CFLOGIN Authentication Using IIS

Saturday, November 30, 2002 5:56:56 PM

After much trial and error using IIS and ColdFusion MX, I've found a problem with the CFLOGIN authentication system. The problem is in the default IIS settings. To get the <cflogin> tags to work properly -- allowing the setCredentials() method to work in Flash Remoting -- you need to open up IIS admin interface and right-click on your Web application and choose Properties > Directory Security > Anonymous Access > Edit. Here you will have to uncheck the Integrated Windows Authentication. Using integrated authentication only allows users that are set up under Windows to access pages in a directory protected by a <cflogin> system. The <cflogin> system works perfectly with the built-in CFMX web server. Screenshot of the admin interface of IIS here.

Add comment (1)
View comments

Flash Remoting for ASP.NET -- No errors on expiration

Friday, November 29, 2002 7:52:12 PM

After working with the trial version of Flash Remoting for ASP.NET for a while from the local computer where it was installed, I was trying out a new DLL from another computer. Apparently the trial 30-day version had expired, but I didn't realize it. The Flash environment did not show any errors -- even with the debugger turned on. I finally figured out the problem when I examined the Flash logs. After installing the full version, the DLL suddenly worked. I was expecting an error message like the one that is seen when accessing a ColdFusion service from Flash, such as "licensed for development only" or something along those lines. I didn't expect the debugger to stop dead in its tracks. One more for the wish list. . . .

Add comment (1)
View comments

More on ASObject for ASP.NET

Thursday, November 28, 2002 11:37:15 AM

The myASObject.Add("myProperty","myValue") does not work when the property already exists. For that, just set the property directly:

myASObject["myProperty"] = "myValue";

Add comment (0)
View comments

1-5 | 6-10 | 11-15 | 16-20 | 21-25 | 26-30 | 31-35 | 36-40 | 41-45 | 46-50 | 51-55 | 56-60 | 61-65 | 66-70 | 71-75 | 76-80 | 81-85 | 86-90 | 91-95 | 96-98