If you have been using the
Flash Player 10 RC and came across a site or widget using SWX, you undoubtedly noticed that it wasn't working. After a couple of days of back-and-forth on the SWX mailing list, the issue has been found and a solution posted.
[Update September 5, 2008 - a different fix was suggested in an attempt to allow SWX to continue to be used by hitting the gateway directly, allowing for easier debugging. Code below reflects this update.]
The problem is that FP 10 does not like one of the headers returned from SWX. To fix the issue, open SwxAssembler.php and change line 538 from:
header('Content-Disposition: attachment; filename="data.swf"');
to:
header('Content-Disposition: inline; filename="data.swf"');
This seems to fix the issue, as all SWX sites this has been tested on now work in FP 10 again.
Thanks to FabrÃcio Kolling for finding the proper solution, and to Folkert Hielema and Ben Lagoutte for helping test broken sites and debug the issue.
While this issue has not yet been fixed in the project's SVN or downloads, we hope to make this addition soon and release an updated version with the last couple of minor fixes.
When working with SWX RPC, you don't want to continuously serialize complex arguments by hand when call server-side methods. And you don't have to, if you use the prepare() method of the SWX class in the SWX ActionScript Library that comes with SWX PHP.
Save your FLA in the flash/ folder (the one that has the org and com folders) before continuing. (Or add that folder to your ActionScript classpath in the Flash IDE and save your FLA anywhere.)
Modify the code sample so that it matches the listing below:
import org.swxformat.SWX;
dataHolder.serviceClass = "Calculator";
dataHolder.method = "addNumbers";
dataHolder.args = [35, 7];
dataHolder.debug = true;
SWX.prepare(dataHolder);
dataHolder.loadMovie("http://localhost:8888/php/swx.php", "GET");
function onEnterFrame()
{
status.text = dataHolder.result;
}
The prepare() static method of the SWX class simply serializes your arguments into JSON format for you. Notice that the args property in your dataHolder is no longer a string but an ActionScript array with two numbers inside it.
This is definitely far better than manually serializing your arguments by hand but it's still not ideal, is it? For one thing, that onEnterFrame function we're using is not a good practice. It would be really nice if we could have an event handler called when the data arrives instead of polling for it. The SWX ActionScript Library provides that functionality for you too.