[swx] Catching PHP parse errors on Flash
Fabrício Seger Kolling
dulldusk at gmail.com
Tue Sep 25 11:04:09 PDT 2007
I've modified SWX so that i can return more information to flash.
ExternalAsset._innerMovie.result[0] is now an object with five properties.
error : Boolean - indicates is there was a user generated fatal error,
leads to ExternalAsset.FAULT
errorMsg : String - the fatal error message
log : String - for debbugging server side scripts
output : String - i use php output buffering to catch and parse into the
swf any output previous to its generation
data : Any Type - the actual data result from the method execution
log and output properties only return when SWX is called on debug mode.
The problem with PHP parse erros is that they are generated before the
script execution, and always result on a plain text output, that can't
be avoided or catched with output buffering.
But when that happens, soon after _innerHolder.loadMovie(),
_innerHolder.getBytesTotal() starts returning -1.
So I stop the loader, and call ExternalAsset.loadPlainText() that uses
LoadVars() to get the parse error and output it on flash.
public function loadPlainText(){
log("SWX Calling method load on plain text mode");
var thisRef = this;
_loadVars = new LoadVars();
_loadVars.onData = function(src:String) {
if (src.length > 102400) {
src = "> 10Kb";
} else if (src != undefined){
src = Strings.trim(Strings.removeHTML(src));
}
thisRef.log("SWX Server Return:\n" + src);
};
_loadVars.onLoad = function(success:Boolean) {
};
if (_dataObject == null) {
_loadVars.load(_gateway, _loadVars, _encoding);
} else {
for (var i in _dataObject) {
_loadVars[i] = _dataObject[i];
}
prepare(_loadVars);
_loadVars.sendAndLoad(_gateway, _loadVars, _encoding);
}
}
It's more to tell you guys the solution i came up, error handling can be
a real pain.
Fabrício
More information about the swx
mailing list