Solved

Flash AS2 load multiple xml files

Posted on 2009-07-09
14
785 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

This article describes a solution to a problem of subloading one movie into another when they have different SWF versions. Sometime back, I was working on an ActionScript project while I came across an interesting fact which I would like to share…
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 how to record live broadcast.
Suggested Courses

734 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