ColdFusion Muse

Flash Forms and the local shared object

Mark Kruger May 6, 2005 6:09 PM CFMX 7 Flash Forms, Coldfusion MX 7 Comments (2)

Coldfusion MX version 7 gives us a great new feature when using <CFFORM>. It renders the forms in a flash form. The look is clean and the result is well behaved and intuitive. We've had a lot of fun creating prototypes using flash form grids and the accordian pane or tabbed interface. It's great to be able to create a form with tabs that doesn't require round trips to the server and has solid validation routines. Along the way we hit a couple of challenges and came up with a few solutions ....

p>One of the frustrations we have is that the full universe of actionscript is not available to us. There are times when we want more granular control over the elements that are contained within a server-generated form. The only thing you can do is to add scriptlets to the event handlers for particular form elements. Why is this frustrating you ask? One of the problems we tried to solve is providing a preview of data that is dynamically populated as the user is filling out the form. This is important on a complex form where the data is related.

In our case we simply wanted to update a text area with information related to user choices and helpful hints and clues as to how they are doing. This is possible in the flash form using a text area or (I suppose) a cfformitem and manipulating the value attribute. Neither approach was ideal because it's difficult to write complex actionscript commands inside the handlers. For example, MM in their wisdom removed the "new" key word so you cannot create any "new" object.

Shared Object Solution

One solution that I thought was cool enough to mention was the shared object solution. We created a flash movie that has a visible text area nicely formatted. We added code to the move that polled a shared object periodically and updated the text field. Yes, I know the localConnection object would be much better for this, but since I can't use new in the flash form actionscript I cannot create the connection object on that side (sigh). sharedObject() doesn't require a "new" keyword however so we can use it. Here's the code we used for the polling object (1 time per second).

function setHelp() {
   
var so:SharedObject = SharedObject.getLocal("help", "/");
   
   if(so.data.str != undefined || so.data.str != help_txt.htmlText) {

      help_txt.htmlText = so.data.str;
   }
}

_global.intervalID = setInterval(setHelp,1000);

It's not rocket science. It just checks to see if there's anything in the shared object to display.

On the flash form it's a little tricker. To get the actionscript necessary into shared object we have to run the following code:

var so:SharedObject = SharedObject.getLocal("help", "/");
   
   so.data.str   =   ... a string of information ....;
   
   so.flush();

The idea is to set the shared object to value to some string of information and then flush it to the disk. The polling process on the helper movie picks it up and displays it. While it works quite well I would still call this a "work around". They should give access at least to the localConnection object for this sort of interactive purpose. I can think of all sorts of nifty uses.

  • Share:

2 Comments

  • Michael White's Gravatar
    Posted By
    Michael White | 8/20/05 10:49 AM
    can this be used for date objects... say if you wanted to calculate the difference between dates or times?
  • Mark's Gravatar
    Posted By
    Mark | 8/20/05 11:01 AM
    As I recall, the "data" object can contain anything. So, if you can figure out how to create a date object inside the flash form you could send it to the shared object, pick it up and calculate against it. Of course it may be more easy to send a string and parse it into a new date object. Remember that the main frustration with flash forms is the limitations on actionscripting.