• Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
    Dedicated community for Japanese speakers
  • 한국 커뮤니티
    Dedicated community for Korean speakers
Exit
0

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

New Here ,
Feb 03, 2022 Feb 03, 2022

Copy link to clipboard

Copied

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?

TOPICS
ActionScript

Views

94

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

LEGEND , Feb 03, 2022 Feb 03, 2022

This ought to work:

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

Votes

Translate

Translate
LEGEND ,
Feb 03, 2022 Feb 03, 2022

Copy link to clipboard

Copied

This ought to work:

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

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Feb 04, 2022 Feb 04, 2022

Copy link to clipboard

Copied

LATEST

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

 

Thanks!

Votes

Translate

Translate

Report

Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines