Solved

Flash AS2 load multiple xml files

Posted on 2009-07-09
14
782 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
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.

 
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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Sometimes you know that one object has a specific child in it, but you can't find the child. This happened to me when I was trying to code some actionScript to make a toolbar work with its embedded buttons.  My partner had created the toolbar usi…
In my long career of working as an actionscript developer, I had spent sleepless night often working hard to solve some small problems which actually took a lot of my development time; later found out the solutions to be a line or two. Here are s…
In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
The goal of the tutorial is to teach the user how to live broadcast using Flash Media Live Encoder and connecting it to YouTube to broadcast. Log into your Youtube account, choose live stream settings, start live stream from Flash Media Live Enc…

821 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