Solved

Flash AS2 load multiple xml files

Posted on 2009-07-09
14
773 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
 
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
What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

 
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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Error 2032 in all the browser 6 2,800
Google Chrome Blank White Screens 13 283
Accessing Live Dynamic Stream 6 180
blocked plugin flash 5 107
This is a very simple example to help those of you who are still migrating from AS2 to AS3 understand the redesigned event model in AS3. In AS2.0, event functions (that is, the function to be performed when an event is fired) were stored as a pro…
Introduction This article is primarily concerned with ActionScript 3 and generally specific to AVM2.  Most suggestions would apply to ActionScript 2 as well, and I've noted those tips that differ between AS2 and AS3. With the advent of ActionS…
The goal of the tutorial is to teach the user how to how to record live broadcast.
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.

744 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

10 Experts available now in Live!

Get 1:1 Help Now