PDA

View Full Version : Filename as variable



digitalpazzo
May 8th, 2007, 07:18 AM
Hi,
I have the following problem: I am loading a flash movie into another flash movie (actually into the MonoSlideShow (http://www.monoslideshow.com)). I can only place the different movies I want to load in a single folder called images but it can't containt subfolders. This would be no problem since I could give every movie inside the images folder a different name. However each of those movies loads an XML file. In the future I do not want to touch the FLA files and if I add another movie into the images folder it should automatically load the correct XML file (which by the way all are placed in the same folder as the movies). So since I don't know what the movies are going to be called or how many there are going to be I can't specify the correct XML filename in advance! So my question is: can I specify a variable that changes according to the filenmae of my swf file (example: filename of the swf file = test1 so then the swf movie knows that it should load the XML file test).?

Thanks,

Dazzer
May 8th, 2007, 08:07 AM
you mean, can you use flash to detect the number of files in the folder, and change its variables accordingly? no.

security box does not allow any access to local assets

efos
May 12th, 2009, 03:30 PM
I believe he wants to know how to access the swf's filename, then load an XML file of the same name.

try this:

var sURL:String = this.loaderInfo.loaderURL;
var aURL:Array = sURL.split("/");
var sFilename:String = aURL[aURL.length-1].slice(0,-4)+".xml";
trace(sFilename);And if you one line that, no one will like you.


var sFilename:String = this.loaderInfo.loaderURL.split("/")[this.loaderInfo.loaderURL.split("/").length-1].slice(0,-4)+".xml";
trace(sFilename);it burns us!

Oops, sorry about the necropost. I was looking for this method myself, didn't notice the date.