I seem to be running into an interesting problem while saving a Sprite to my server. When I run the swf (remote) on my MAC it works fine but when I run the exact same URL from my windows computer I get a #2048 SecurityError.
Here my AS3 code:
public function saveSprite(s:Sprite):void {
var bmpData:BitmapData = new BitmapData(s.width, s.height, true, 0xFFFFFF);
bmpData.draw(s);
var byteArray:ByteArray = PNGEncoder.encode(bmpData);
var encodedFile:Base64Encoder = new Base64Encoder();
encodedFile.encodeBytes(byteArray);
var data:URLVariables = new URLVariables();
data.fileData = encodedFile;
data.fileName = "test.png";
data.location = "temp/";
var request:URLRequest = new URLRequest(scriptLocation);
request.method = URLRequestMethod.POST;
request.data = data;
var loader:URLLoader = new URLLoader();
loader.addEventListener(Event.COMPLETE, errorLog);
loader.addEventListener(Event.OPEN, errorLog);
loader.addEventListener(HTTPStatusEvent.HTTP_STATUS, errorLog);
loader.addEventListener(IOErrorEvent.IO_ERROR, errorLog);
loader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, errorLog);
loader.addEventListener(ProgressEvent.PROGRESS, errorLog)
try {
loader.load(request);
} catch (e:*) {
debug.updateLog(e + "\n");
}
}
private function errorLog(e:*):void {
debug.updateLog(e + "\n");
}
The AS3 connects with the following one-line PHP-file:
<?php file_put_contents($_POST['location'] . $_POST['fileName'], base64_decode($_POST['fileData']));
When I run the SWF on my mac the output is as follows: Log Start [Event type="open" bubbles=false cancelable=false eventPhase=2] [ProgressEvent type="progress" bubbles=false cancelable=false eventPhase=2 bytesLoaded=7 bytesTotal=0] [HTTPStatusEvent type="httpStatus" bubbles=false cancelable=false eventPhase=2 status=200 responseURL=null] [Event type="complete" bubbles=false cancelable=false eventPhase=2]
Where on a Windows I get the following output: Log Start [HTTPStatusEvent type="httpStatus" bubbles=false cancelable=false eventPhase=2 status=0 responseURL=null] [SecurityErrorEvent type="securityError" bubbles=false cancelable=false eventPhase=2 text="Error #2048"]
Any thoughts on this will be appreciated. My own guess would be something with file permissions but what?
Thanks in advance!
[EDIT] It gets more interesting. 1. When I move my whole project to a different server I get a #2048 on windows and mac. 2. If I change my file permissions to 777 I get a #2048 on windows and mac as well.