I'm trying to load data from a simple php file. I'm getting an IOErrorEvent message that states: "Unable to make request (may be blocked due to cross-domain restrictions)" This works find in AS3, but I'm trying to get it to work in Haxe + OpenFL (targeting HTML5). The code successfully posts the score, but doesn't COMPLETE the load (throwing an IOErrorEvent).
import openfl.net.URLVariables;
import openfl.net.URLRequest;
import openfl.net.URLLoader;
import openfl.events.IOErrorEvent;
import openfl.events.SecurityErrorEvent;
import openfl.system.Security;
public function save() {
Security.allowDomain("www.roomrecess.com");
Security.allowDomain("roomrecess.com");
var sender:URLLoader = new URLLoader();
var myVar:URLVariables = new URLVariables();
myVar.score = score;
var website:URLRequest = new URLRequest("http://www.roomrecess.com/php/boomSave.php");
website.data = myVar;
sender.addEventListener(Event.COMPLETE, loadComplete);
sender.addEventListener(IOErrorEvent.IO_ERROR, IOEErrorHandler);
sender.addEventListener(SecurityErrorEvent.SECURITY_ERROR, SecEvHandler);
sender.load(website);
}
public function IOEErrorHandler (e:IOErrorEvent)
{
ground[0].visible = false;
scoreDisplay.text = e.text;
scoreFormat.size = 10;
scoreDisplay.setTextFormat(scoreFormat);
}
public function SecEvHandler (e:SecurityErrorEvent)
{
ground[4].visible = false;
}
public function loadComplete(e:Event) {
Security.allowDomain("www.roomrecess.com");
Security.allowDomain("roomrecess.com");
background.visible = false;
sender.removeEventListener(Event.COMPLETE, loadComplete); //changed from loader to sender to match save()
outputTxt.text = e.target.data;
bytes = outputTxt.text;
mystring = bytes.toString();
stats = mystring.split(" "); //changed from int array to string array
standings();
loadCompleteVar = true;
}