Flash MX 2004 sendAndLoad bug

Here is a bug that I wasted untold hours on.  sendAndLoad is a method available on Flash 6 and later feature that sends and receives URL encoded name/value pairs.  For example:

var in = new LoadVars();
var out = new LoadVars();

in.onLoad = function (success) {
   if (success) {
      // got response
   }
};

out.somedata = 'hello world';
out.sendAndLoad('hello.cgi', in, 'POST');

In the above example, I've used an anonymous function to handle the response.  Unfortunately, Flash MX 2004 generated Flash movie doesn't call anonymous function onLoad handler if the movie output settings are Flash version 6 and ActionScript version 1.  The workaround is simple: use a named function like this.

function loadHandler (success) {
if (success) {
      // got response
   }
};

var in = new LoadVars();
var out = new LoadVars();

in.onLoad = loadHandler;

out.somedata = 'hello world';
out.sendAndLoad('hello.cgi', in, 'POST');

Advertisements