views:

706

answers:

2

Okay getting some weirdness. I have a simple URLLoader in AS3 that loads an external XML document. It's loading just fine, I get a correct 302 Not Modified response in Charles, however flash tells me:

"URL Not Found"

Here is 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've verified that I can browse to the URL via my browser and cURL, and Charles says that my SWF can and IS successfully accessing it too. However I still get this URL Not Found error. According to the Flash Actionscript 3 documentation, this is the absolute correct way to use URLLoader to load external data including XML.

Updated code with pastie.

+1  A: 

Without knowing all of the details, and assuming you implemented the RESTful services properly, your URLRequest might be calling the service with the wrong method (POST, rather than GET).

Check out this tutorial about calling RESTful services from Actionscript 3:

Consuming REST web Services in ActionScript 3

It has some good info on setting the request type and dealing with some of the other issues that can pop up (like setting the return data type, etc.).

Justin Niessner
To add, I checked it out in Charles and it is making a GET request, I have no hardcoded that in there, but it was making one. Thanks for the link.
Zach
You could always hard code the request type and response format just so you can rule those out (always better to hard code them in case Adobe decides to change its defaults or something).You might want to try adding some error event handles to the object as well...could provide a little more feedback.
Justin Niessner
Sorry I meant to write now, but here's a little thing I've found I added an IOErrorEvent handler and it doesn't appear to be catching the error, which is what the error type is. My thinking is perhaps that listeners aren't getting added correctly somehow, if not could that be throwing this error?
Zach
Double check the rest of your code. Make sure you don't have another request being made somewhere. If it was this request, your IOErrorEvent would catch it (can't know for sure without the new source).
Justin Niessner
Alright I double checked it and then stepped it line by line again with the updated code and the same thing. I updated the question with my new code. It's at pastie at the very bottom. I did pastie because I like how the format better and just feel it's easier on the eyes. Hope you don't mind.
Zach
+2  A: 

I'm finding your code's structure a little odd - why do you have functions inside of a function?

I rewrote your code like this and it works perfectly fine (i just ran it on the timeline in flash cause 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');
quoo
quoo, I don't know why this worked but it did. Once again you've helped me. Also thanks for that Charles proxy tip, that really helped me figure out what was going on with other things in my swf as well. No idea why it was voted down. Seems like there has been an influx of children on this site as of late.
Zach
well, i'm glad the charles stuff helped you anyway - just be careful, if you're getting a lot of invalid security certificates, it's probably because of this:http://www.charlesproxy.com/documentation/using-charles/ssl-proxying/
quoo