• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 876
  • Last Modified:

actionscript read xml file from parent folder


Quick question.  I have a but of code that imports values from an XML file & everything works fine.

archiveXML = "http://www.sampleSite.com/2008/XMLinfo.xml";

What i need to do is make sure that i do not have to hard code in the URL as above. I need this to import the file no matter what website it is on. The file will always reside in the sample folder hierarchy. Is there anyway that i can set it up so it knows that the file resides back 2 parent folders.

For example, the website structure will be


The flash movies will always be in the one of the day folders.

If the XML file will always be in the year folder.

so is there a way to call the file from 2 folders back

or something like that ?

  • 2
  • 2
1 Solution
The use of ../../ is correct, however, the source location needs to be referenced from where the HTML file is located and not where the .swf is.

i.e. if the index page located on the root directory loads in the swf from year/month/day/flash.swf
The URL to find the XMLinfo.xml file would be year/XMLinfo.xml

If the HTML that is loading the swf is located in the same directory as the flash.swf file then the URL would be ../../XMLinfo.xml
headsyAuthor Commented:
the html page that is loading the SWF is in the same folder as the swf. so how do i change the code in actionscript

to read from the 2 tier parent directory

archiveXML = "http://www.sampleSite.com/2008/XMLinfo.xml";

This should work for you.
function loadupdate(loaded) { 
if (loaded) { 
//do this when xml is loaded
xmlData = new XML(); 
xmlData.ignoreWhite = true; 
xmlData.onLoad = loadupdate; 

Open in new window

If the above doesn't work for you, here's some code that will actually get the SWF's current URL and then "step it back" 2 levels to get the parent's parent directory (or any number of steps back that you want). I'll upload the whole ZIP if I can in a later post.
// getParentDirectory - this will grab the SWF's current URL
// (not the URL of the html file that calls the SWF) 
// and will allow you to "back out" any number of parent levels. 
// I have not error-trapped the function so use with caution,
// or modify to suit your needs.
var swfURL:String; // this will contain the SWF's url information
// this one for AS3
swfURL = loaderInfo.url;
// this one for AS2
// swfURL = _url;
var parentURL = getParentDirectory(swfURL, 2);
// this function could have been written with RegExps for AS3, but
//this should work for both AS3 and AS2
function getParentDirectory(urlString:String, numberOfSteps:Number = 1):String{
	var parentDir:String = urlString.substr(0, urlString.lastIndexOf("/"));
	if (--numberOfSteps){
		parentDir = getParentDirectory(parentDir, numberOfSteps);
	return parentDir;
// let's pretty it up and throw it into some textboxes on screen
txtFullURL.text = swfURL;
txtExtractedURL.text = parentURL;

Open in new window

I couldn't upload the source - I guess EE restricts file types. Just copy and paste from the window above and create two appropriately-named text fields.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now