Flash AS2 load multiple xml files

Could someone please take a look at the following code and see where I am going wrong. I am trying to cycle through several xml files, load the contents and trace them out.

But what seems to be happening is all the load instructions are being done one after the other, before the onLoad function can run.

Thanks for any suggestions you can offer.

Mark


//initial loop
for (i=0; i<5; i++) {
      getMovies(i);
}


function getMovies(game) {
      
load_xml = new XML();
load_xml.ignoreWhite = true;
load_xml.onLoad = function(success) {
if (success) {
      
      trace("GAME "+game);
      trace("XML "+load_xml);

} else {
      trace("cannot find "+game);
}

}

trace("LOADING NewName/"+game+"/info.xml");
load_xml.load("NewName/"+game+"/info.xml");
      
}



This is the trace output I get: As you can see, only the last item records the xml content

LOADING NewName/0/info.xml
LOADING NewName/1/info.xml
LOADING NewName/2/info.xml
LOADING NewName/3/info.xml
LOADING NewName/4/info.xml
GAME 0
XML
GAME 2
XML
GAME 3
XML
GAME 4
XML
GAME 11
XML <?xml version="1.0" encoding="UTF-8"?>
LVL 13
crooksy88Asked:
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.

blue-genieCommented:
Hi, what do you ultimately want to achieve with this, because if you do it in a for loop each time you're replacing the load_xml with the data from the next loop and it will always be the last item.

if you're just trying to store the data  you can try populating them xml into an array which you can then access later.
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
crooksy88Author Commented:
Hi blue-genie,

I had that thought and tried it out but obviously was still doing something wrong as I just recorded the same xml in each array element. i.e. 5x the contents of the last xml file to be loaded.

What I ultimately want to do is load the xml, collect some nodeValues and push them to an array, then discard that xml and load the next one etc.

I'm only tracing things out at the moment to see what's going on.

Can you show me what needs to change in my code in order for me to load one xml file, collect data, discard the xml, then load the next?

Thanks,

Mark
0
crooksy88Author Commented:
I've set the code back up to try to populate an array with the xml contents but I can't figure out how I would cycle through the xml files without using a for loop?
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

blue-genieCommented:
can you upload your xml files and give me an example of what you want to store.

0
crooksy88Author Commented:
Are you using CS3 or CS4?
0
crooksy88Author Commented:
No matter, I've created a test flv for both.
You can download the files (inc xml) using this URL

http://www.infin8design.com/clients/ee/test.zip

As you test the movie you will see that currently the first 4 entries into the array are undefined.
What I'm wanting to end up with is an array containing 4,0,0,4,4.
(this is the correct result for the contents of the supplied xml files).

Many thanks for your help on this.

Mark
0
rascalpantsCommented:
are you using AS 2 or AS 3?


rp
0
crooksy88Author Commented:
AS2
0
rascalpantsCommented:
I would personally setup 5 different XML objects and load the data individually into each one.

that way you can parse what you need, only when needed...


too bad you cannot use AS 3...  the new E4X allows for great searching and parsing.


rp
0
crooksy88Author Commented:
That sounds OK but the amount of xml objects is variable. i.e. one day there might be 5, the next there might be 20.

Is it possible to set up the different XML objects in this dynamic way? And if so, would you be able to draft a bit of Actionscipt (2) so I can see how this would be done?

Thanks,

Mark
0
rascalpantsCommented:
okay, now we are getting into programming theory here...  and possibly your approach to this application needs to be rethought.

why are there so many XML files... why wouldn't you just use one larger one and parse as needed?


you already have this hard coded as "5"  so you will have to update the code anyway...


rp
0
crooksy88Author Commented:
Unfortunately there are reasons why the xml is split into individual files.

I was hoping that the reason I was struggling with this problem was to do with my lack of knowledge rather than it being a complicated task.

But your comments have made me rethink how I could get the data that I required and I have managed to do so by other means.

Thank you both for your replies and comments.

0
crooksy88Author Commented:
Understood! thanks.
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
Adobe Flash

From novice to tech pro — start learning today.