OnLoad event in ColdFusion Flash Forms Part I

One of the missing features in Flash Forms is the onLoad event. I'm not sure why they left it out since the attribute works for xforms and regular html forms, in which case the tag expects a piece of JavaScript code. It would make sense to expect a piece of ActionScript code for Flash forms.


One of the missing features in Flash Forms is the onLoad event. I'm not sure why they left it out since the attribute works for xforms and regular html forms, in which case the tag expects a piece of JavaScript code. It would make sense to expect a piece of ActionScript code for Flash forms.

In any case, because this event would come in handy in several scenarios, I made a workaround while we wait for a real onLoad event from Macromedia ( crossing fingers here).

You can view a working example that fires an alert when the form is loaded.
The code looks like this:

alert("An Alert generated with the onLoad Event ",'Your on load Event',mx.controls.Alert.OK); label1.setFocus(); {(trigger.text != '') ? trigger.dispatchEvent({type:'change'}) : 'init'}

I used a dummy cfinput (named "trigger ") to fire the event that allows having a simple onLoad event. However, this implementation has some limitations that I will address in the next post in order to keep this example simple.


Limitations to be aware of:

  • The "trigger" input has to be placed after all the other controls if we want to access any of them from the onLoad event
  • It does not have access to any value of the controls. This is due to the onLoad event getting fired before any value is set.
View the example
Download the source

Update: This hack is no longer needed after ColdFusion updater 7.01