XML not loading in AS3

I’m very new to actionscript and I’m having an issue loading some XML. The code works fine when I “publish preview”. It also works if I open the html generated when I publish. But the xml isn’t loading if the published swf is called from any other html file.

Here is the code than I’m using:

var loader = new URLLoader();
loader.load(new URLRequest(“playlist.xml”));
loader.addEventListener(Event.COMPLETE, xmlLoaded);

the Event.Complete event isnt getting dispatched, and xmlLoaded is never called…

Any ideas?

OK. I’m not sure why, but t works if the swf, xml, and html are in the same folder. So now my question is this: How does the swf know that it is being included from a file in a different directory…and more importantly…why does it matter?

I probably didn’t state my question clearly. I know why I have to specify the exact location of the xml in my actionscript. The flash file and the xml file are in the same directory and therefore the path is simply “playlist.xml”

Given the following two scenarios, it doesn’t make sense why I would get different behaior.

Scenario 1: swf, xml in the same directory. Html in the directory above and I use swfobject to load the swf. The swf loads fine, but it doesn’t load the xml.

Scenario 2: swf, xml, and html are in the same directory and xml loads fine.

Keep in mind, there is no reference to the xml anywhere in my html file. It is loaded directly from the swf. If the swf has the correct path to the xml…it shouldn’t matter where the html is…

It matters as you need to tell the application from where it should load a content, it cant just go on searching every directory on its own and its also not logical. If you have placed the xml file in a particular folder then you need to specify the entire file path or use a relative file path.

The path is always relative to the embedding html page. When a swf is loaded via html it takes the location of the html page as the root location to calculate a path from, so the results are as expected.

Interesting. That definitely explains why I was having problems. Thanks :slight_smile: