Skip to main content
cornbread02
Inspiring
February 4, 2022
Answered

Is it possible to use Loader with variables in the String name? AS3

  • February 4, 2022
  • 1 reply
  • 264 views

I guess this is very simple. Stage has a textField (filenumEnter) and a button (setinfo_btn). The goal is loading a specific local file (with naming protocols being "file1.xml" etc.) without having to use FileReference. I have had success in hard coding a limit of documents, but thinking about situations where somebody creates 30 files and wants to access, for example, file 22. You can't just set it up like this:

var fileNum = filenumEnter.text;

var xmlLoader:URLLoader = new URLLoader();
xmlLoader.addEventListener(Event.COMPLETE, loadXML);
var xmlData:XML = new XML();

function loadXML (e:Event): void {
xmlData = new XML(e.target.data);
trace(xmlData);
} //My focus is on the below function

function fileLoad(event:MouseEvent): void {

if (event.currentTarget == setinfo_btn) {
fileNum = filenumEnter.text;
xmlLoader.load(new URLRequest("file[fileNum].xml"));
}

 

So I am hitting a minor roadblock on how to do this with the user entering a number in the textField. I guess I could use a comboBox instead, but then wouldn't I have to update it everytime to make sure it is up to date?

This topic has been closed for replies.
Correct answer Colin Holgate

This ought to work:

xmlLoader.load(new URLRequest("file"+fileNum+".xml"));

1 reply

Colin Holgate
Colin HolgateCorrect answer
Inspiring
February 4, 2022

This ought to work:

xmlLoader.load(new URLRequest("file"+fileNum+".xml"));
cornbread02
Inspiring
February 4, 2022

Of course! Something so simple, I just completely forgot about it. Goodness!

 

Thanks!