Flash Remoting.com
Home Book Examples Blog Resources About

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. ;-).

6 posts in December 2002.

[ALL] 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

1-5 | 6-6

New arguments for DW api call dw.newFlashFloater()

Monday, December 23, 2002 3:04:29 PM

In Dreamweaver 6.0, Flash panels had a few bugs that prevented them from connecting to the internet when docked--which prevented Flash Remoting from working in a Dreamweaver extension. Also, docking was a nightmare because you had to embed the .swf into an HTML file and create the API functions for IsTarget, IsDockable, etc. The 6.1 updater for Dreamweaver MX fixed the Flash floater functionality.

dw.newFlashFloater is not documented in the Extending DW manual, but it was there. Now there are two new arguments: dockSide and isTarget. Note that this is an undocumented feature and as such it might not be available in future versions of DW.

dw.newFlashFloater(swfpath, floatername, [groupname],[tabname],[scalemode],[dockside],[isTarget])

swfpath is the local path of the flash swf file. Usually the best way to handle this is to put the swf into the floaters directory and then grab the local configuration directory:

var configDir = dreamweaver.getConfigurationPath();
var thePath = configDir + '/Floaters/myFloater.swf';

Floatername is the name of the floater which is used in calls to dw.toggleFloater()

Groupname is an optional parameter. If you specify a group (such as "Code" or "Design") the floater will be opened in that group. If not, a new group will open with the floater name.

tabname is an optional parameter to name the tab of the floater. If it is not specified, the tab name will be the floater name

scalemode is the Flash movie scaling style. This is set to -1 by default (I don't have any other info on this.)

dockside is a string of sides that the floater can dock to, like "left right top bottom" or "left right"

isTarget is true or false and allows other panels to be docked in the group with this panel.

To add a Floater to Dreamweaver, I usually create a DW command file:

<title>My Floater</title>
function canAcceptCommand() {
  return true;

function toggleMyFloater() {
  var configDir = dreamweaver.getConfigurationPath();
  var thePath = configDir + '/Floaters/myFloater.swf'
  dw.newFlashFloater(thePath,'myFloater', 'Code', 'My Floater', -1, 'left right', 'true');


<body onLoad="toggleMyFloater()" ></body>

Then in the MXI, include the command file and the floater file, and write to the DW menu:

<macromedia-extension name="My Floater" version="1.0.0" type="floater">
  <author name="Thomas Muck" />
    <product name="Dreamweaver" version="6" primary="true" />
       Simple test of Flash floater.
       You can run this Panel by choosing:<br>
       Window > Others > My Floater
    <file source="myFloater.htm" destination="$dreamweaver/configuration/Commands/" />
    <file source="myFloater.swf" destination="$dreamweaver/configuration/Floaters/" />
    <menu-insert insertAfter="DWMenu_Window_Sitespring">
      <menuitem name="My Floater"
       id="DWMenu_Window_myFloater" />

A floater made this way for Dreamweaver can also be utilized in Fireworks or Flash. In Fireworks MX, put the .swf file into the <your drive>\Macromedia\Fireworks MX\Configuration\Command Panels folder. In Flash MX, the folder is usually in the multi-user folder. On a Windows 2000 machine, this would be at: C:\Documents and Settings\[username]\Application Data\Macromedia\Flash MX\Configuration\WindowSWF.

For Flash and Fireworks, no menu or api calls are necessary. The panel can be dropped in the folder and it will work.

Add comment (3)
View comments

CF.query Method for ServerSide ActionScript in JRun

Wednesday, December 18, 2002 10:12:15 PM

I've created an object for JRun 4 ServerSide ActionScript that adds a CF.query() method to SSAS. Basically, all you do is add this code to your .asr file and call CF.query() just as you would if the SSAS file were on a ColdFusion server. The only arguments supported right now are datasource and sql. The datasource must be a valid JRun 4 data source set up in the JRun administrative interface. The sql parameter can be any valid SQL, although I've only tested with simple select, insert, update, and delete statements. The code could be modified easily enough to custom-fit for other types of statements, such as stored procedures that return resultsets. I tried to keep it simple for this example.

CF = new Object();
CF.query = function(datasource, sql) {
  // InitialContext for JRun data source names
  var ctx = new Packages.javax.naming.InitialContext();
  // find data source
  var ds = ctx.lookup(datasource);
  var dbConnection = ds.getConnection();
  var stmt = dbConnection.prepareStatement(sql);
  // If it is a SELECT statement, return a resultset
  if(sql.match(/^select\s*/i)) {
    var rs = stmt.executeQuery();
    var rsmd = rs.getMetaData();
    var myRecordSet = new Object();
    myRecordSet.columnNames = getColumnNames(rsmd);
    rs_hasData = rs.next();
    if(rs_hasData) {
      myRecordSet.items = serializeData(rs, myRecordSet.columnNames);
    myRecordSet.totalCount = (rs_hasData) ? myRecordSet.items.length : 0;
  }else{ // Not a select statement
    return stmt.executeUpdate();
  return myRecordSet;

// Get the column names of the ResultSet
function getColumnNames(metadata) {
  var columns = new Array();
  for(var i=1; i<= metadata.getColumnCount(); i++)
  return columns;

//Serialize the data for returning to Flash
function serializeData(rs, columns) {
  var rs_hasData = true;
  // rows holds the rows
  var rows = new Array();
  // currentRow will hold individual row
  var currentRow = new Object();
  // z is a mapping -- integer indexes that match column names
  var z = new Array();
  var columnCount = columns.length;
  // get index mapping of column names
  for(var i = 0; i < columnCount; i++)
  while (rs_hasData){
    for(i = 0; i < columnCount; i++) {
      currentRow[columns[i]] = (rs.getObject(z[i]));
    // add to our permanent recordset
    // clear the row out again
    currentRow = new Object();
    rs_hasData = rs.next();
return rows;

You call the function just like you do in ColdFusion SSAS:

var myRecordset = CF.query("northwind","SELECT * FROM Products");

The function will return an array of records to the Flash movie. To convert that array to a RecordSet object (so that you can use DataGlue, the DataGrid, and all that other good stuff) you can add a little code to the main timeline to create a new JRunRecordset object:

JRunRecordset.prototype = new Recordset();
function JRunRecordset(rs) {
  super(rs.columnNames); // Call the RecordSet constructor
  for(var i in rs.items)
    this.addItem(rs.items[i]); //add records to RecordSet

After adding this code, you also have to cast any results from the server in your Flash Remoting client-side code as a JRunRecordset, like this:


MyFunction_Result(results) {

change to

MyFunction_Result(results) {
  results = new JrunRecordset(results);

DataGlue should work also. Using this method, examples that utilize SSAS can be used in JRun 4.

Add comment (3)
View comments

Java scripting in ServerSide ActionScript

Wednesday, December 11, 2002 2:57:34 PM

I've been playing with ServerSide ActionScript and have been finding out some interesting things. ServerSide ActionScript is not as limited as many would have you believe. It is based on the Rhino JavaScript engine and is fully scriptable with Java. Java scripting is vaguely similar to the Java language, except it looks like JavaScript. You can call any classes in the java.* package simply by fully qualifying the name:

var myFile = new java.io.File(sourcepath);

Notice that the variables aren't typed as they are in Java. This is the one noticable difference. The other thing is that if you use a class that is not in the java.* package, you have to prepend the package name with "Packages":

var myVar = new Packages.mypackage.myclass();

This opens up a whole world of opportunities for ActionScript developers. Using SSAS you have access to email, the file system of the server, and any other Java construct. For example, this simple script moves a file on the server:

function moveFile(sourcePath, destinationPath) {
  var myFile = new java.io.File(sourcePath);
    return false;
  return myFile.renameTo(new java.io.File(destinationPath));

This is pretty cool for the casual ActionScript programmer who doesn't want to get into the full-blown Java language but still wants to take advantage of some of its power.

Add comment (6)
View comments

No RecordSet for J2EE

Wednesday, December 11, 2002 9:55:12 AM

One of the key uses for Flash Remoting is to return a recordset to Flash -- using CF or ASP.NET this is a piece of cake. The new RecordSet class in Flash deserializes the incoming recordset from the server and allows you to utilize it easily with DataGlue, the DataGrid, or other data consumers in Flash. Using J2EE, however, there is no recordset. This was confirmed in a recent thread in the Macromedia JRun Flash Remoting forum by a support engineer:

"The JDBC ResultSet is not supported by Flash Remoting. The problem is that the ResultSet is a connected result and the data is live therefore it cannot be serialized easily.

There are two ways to return data from a database in FlashRemoting. Either use an ArrayList with a an inner class that represents the row, you will need to loop over the ResultSet and poplulate the ArrayList with the data.

Another way is to use a RowSet, it is not native to the JDBC spec but you can download the classes from Sun.


You will need to use the CachedRowSet which is a disconnected Rowset that can be serialized. You will need to dowload the rowset.jar from the sun site and put it in the /servers/lib directory as well. "

Hopefully we'll see a patch from MM to allow the use of a recordset in Flash Remoting J2EE.

. This also extends to ServerSide ActionScript for JRun 4 -- there is no CF object for the JRun SSAS implementation and therefore no way to get a RecordSet back from the server.

Add comment (4)
View comments

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();

// 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) {
     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;
  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

1-5 | 6-6