Solved

Flash AS2 load multiple xml files

Posted on 2009-07-09
14
776 Views
Last Modified: 2013-11-11
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"?>
0
Comment
Question by:crooksy88
  • 8
  • 3
  • 2
14 Comments
 
LVL 39

Accepted Solution

by:
blue-genie earned 250 total points
ID: 24811450
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
 
LVL 13

Author Comment

by:crooksy88
ID: 24811520
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
 
LVL 13

Author Comment

by:crooksy88
ID: 24812182
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
Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

 
LVL 39

Expert Comment

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

0
 
LVL 13

Author Comment

by:crooksy88
ID: 24812617
Are you using CS3 or CS4?
0
 
LVL 13

Author Comment

by:crooksy88
ID: 24812690
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
 
LVL 22

Expert Comment

by:rascalpants
ID: 24818223
are you using AS 2 or AS 3?


rp
0
 
LVL 13

Author Comment

by:crooksy88
ID: 24818278
AS2
0
 
LVL 22

Expert Comment

by:rascalpants
ID: 24818386
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
 
LVL 13

Author Comment

by:crooksy88
ID: 24818495
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
 
LVL 22

Assisted Solution

by:rascalpants
rascalpants earned 250 total points
ID: 24818677
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
 
LVL 13

Author Comment

by:crooksy88
ID: 24821351
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
 
LVL 13

Author Comment

by:crooksy88
ID: 24823478
Understood! thanks.
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Here are some practices and techniques that can be adopted into your Flash/Flex application development process. Note: Not all "performance tips" provide an immediately-recognizable benefit.   This article does not include timing validation data,…
The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and c…
The goal of the tutorial is to teach the user how to use the auto adjust feature and what the different options do. When your video is not working right you can choose the auto adjust feature to help choose your settings.
This Micro Tutorial will teach to how to utilize bit rate in Adobe Flash Media Live Encoder.

813 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

14 Experts available now in Live!

Get 1:1 Help Now