actionscript read xml file from parent folder

Hi,

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

www.website.com/year/month/day/

The flash movies will always be in the one of the day folders.
www.website.com/year/month/day/flash.swf

If the XML file will always be in the year folder.
www.website.com/year/XMLinfo.xml

so is there a way to call the file from 2 folders back
../../XMLinfo.xml

or something like that ?

THIS IS URGENT, SO I AM AWRDING 500 POINTS.
headsyAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

crooksy88Commented:
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
0
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";

0
crooksy88Commented:
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; 
xmlData.load("../../XMLinfo.xml");

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
tomaugerdotcomCommented:
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

0
tomaugerdotcomCommented:
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.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.