6.1 What Is Server-Side ActionScript?

Server-Side ActionScript is more accurately JavaScript?it is built entirely using the Rhino JavaScript parser (http://www.mozilla.org/rhino). The Rhino implementation of JavaScript was a project begun by Netscape for a never-used all-Java browser. The Rhino project took on a life of its own, however, and is now an open source project housed at the Mozilla web site. Rhino is essentially a JavaScript parser built in Java. For that reason, it is a perfect fit for ColdFusion MX and JRun 4. Macromedia used the Rhino engine for the Server-Side ActionScript implementation in both ColdFusion MX and JRun 4. Currently, these are the only two platforms that support SSAS (the .NET, Java, PHP, and Perl versions of Flash Remoting don't support SSAS).

Flash Communication Server has its own implementation of JavaScript as Server-Side ActionScript, but it is based on the Mozilla Spidermonkey JavaScript engine (written in C). It offers no interoperability with Flash Remoting SSAS. You can find more information about Spidermonkey at http://www.mozilla.org/js/spidermonkey.

SSAS files have an .asr file extension and reside within a ColdFusion or JRun 4 web directory. The .asr files can be viewed in any web browser as plain text files unless you take precautions, such as adding the .asr file extension to the list of excluded file types in your web server.

An SSAS file consists entirely of functions, which become the methods of the remote service that you call with Flash Remoting. You cannot call or execute an SSAS file on its own or through any mechanism other than Flash Remoting. For that reason, SSAS files have these limitations:

  • SSAS files cannot execute inline code, such as variable declarations or other inline statements, except when calling methods. When you call a remote method, all inline code on the page is executed as well.

  • SSAS files cannot include other files, which precludes you from using SSAS to develop server-side classes that reside in separate files.

SSAS consists of the core ECMAScript language, without any of the client-side features you have come to know from writing ActionScript in Flash MX. SSAS uses the same basic expressions, operators, and objects as ActionScript (or JavaScript), but does not include support for movie clips, components, the LoadVars class, XML, or other Flash-specific features. SSAS is intended only for access by Flash through Flash Remoting. It can't be accessed from outside of the Flash environment.

SSAS is stripped to the bare essentials of the ActionScript 1.0 language (the version supported in Flash MX), but it has some added features that may surprise a few ActionScript developers:

  • Full use of regular expressions (the RegExp object)

  • The try/catch/finally construct for error trapping, as in JavaScript

  • The full use of eval( ), which is only partially supported in client-side ActionScript

  • Ability to access Java classes from within SSAS

Using SSAS, you can build server-side objects and methods much like you would build client-side objects and methods. For ActionScript developers that have access to a ColdFusion MX Server, however, the real strength of SSAS is in the new CF object that is specifically designed for Flash Remoting. The CF object has two methods:

CF.query( )

Adds the ability to access ColdFusion data sources with SSAS

CF.http( )

Adds the functionality of the ColdFusion <cfhttp> tag to the SSAS developer's arsenal

These two methods will be the focus of much of this chapter.

The CF object is not available in the SSAS implementation of JRun 4; however, you can use Java classes within SSAS to simulate the CF object, as shown later in this chapter.



    Part III: Advanced Flash Remoting