AS3 url downloader url not found but connects successfully
Okay, you'll get some weirdness. I have a simple URLLoader in AS3 that loads an external XML document. It loads very well, I get the correct 302 Not Modified answer in Charles , however flash tells me:
"URL not found"
Here's the relevant code:
//=============================================================================================
public function openXML(name:String):void { //decides what XML data feed and opens it
//=============================================================================================
var xmlLoader:URLLoader = new URLLoader();
var xmlData:XML = new XML();
//add event listener to URLLoader to call closeXML upon completion
xmlLoader.addEventListener(Event.COMPLETE, closeXML);
xmlLoader.load(new URLRequest("http://www.gessnerengineering.com/projects"));
//=========================================================
function closeXML(e:Event):void {
//=========================================================
xmlData = new XML(xmlLoader.data);
xmlLoader.removeEventListener(Event.COMPLETE, closeXML);
drawPage(name, xmlData);
}
}
The problem line according to the debugger is at:
xmlLoader.load(new URLRequest("http://www.gessnerengineering.com/projects"));
I have verified that I can navigate to the URL through my browser and cURL, and Charles says that my SWF can and IS successfully access it. However, I am still getting this URL Not Found error. According to the Flash Actionscript 3 documentation , this is absolutely the correct way to use URLLoader to load external data including XML.
Updated code from pastie.
a source to share
I find your code structure a little strange - why do you have functions inside a function?
I rewrote your code like this and it works great (I just ran it on the timeline in flash because I'm too lazy to set up a new project):
var xmlLoader:URLLoader = new URLLoader();
var xmlData:XML = new XML();
var request:URLRequest = new URLRequest("http://www.gessnerengineering.com/projects");
request.method = URLRequestMethod.GET;
//=============================================================================================
function openXML(name:String):void { //decides what XML data feed and opens it
//=============================================================================================
//add event listener to URLLoader to call closeXML upon completion
xmlLoader.addEventListener(Event.COMPLETE, closeXML);
xmlLoader.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
xmlLoader.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityError);
xmlLoader.load(new URLRequest("http://www.gessnerengineering.com/projects"));
}
function onIOError(e:IOErrorEvent):void {
trace("Error loading URL.");
}
function securityError(e:SecurityErrorEvent):void {
trace("security error");
}
function closeXML(e:Event):void {
trace('xmlLoader.data ' + xmlLoader.data);
xmlData = new XML(xmlLoader.data);
xmlLoader.removeEventListener(Event.COMPLETE, closeXML);
}
openXML('ljkl');
a source to share
Without knowing all the details, and assuming you have executed the RESTful services correctly, your URLRequest might call the service with the wrong method (POST, not GET).
Check out this tutorial on calling RESTful services from ActionScript 3:
Using REST Web Services in ActionScript 3
He has good information on setting the request type and solving some other problems that may appear (for example, setting the return type, etc.).
a source to share