6 Replies Latest reply on Feb 11, 2013 10:52 AM by moccamaximum

    How to load different xml files when required


      Hi all


      Have searched for answers but can only find information on how to load a single xml file into my flash project.


      My project is a quiz... a preloader, a menu scene, the quiz itself and then a results scene. The quiz scene has a dynamic text box and 4 movie clips for the answers.  The data (questions and answers) is populated from an xml file. At the end of a set of questions the results display. This is all working well for a single xml file but because I have questions in various categories I need to be able to load the corresponding xml.


      So the first button in the menu loads the quiz with data from 1stcategory.xml. Here is where I run into problems. The second button is to load the same quiz scene but with a different xml eg. 2ndcategory.xml.


      I am stumped on how to do this. I read on this forum about loading external swfs (a separate swf for each category) but that's no good for my application because the quiz needs to tally total scores... not just the score for an individual game.


      There surely must be an easy way to code this.


      I would really appreciate any help as I am not able to move forward.


      Below is the actionscript in the quiz scene that I have so far... not sure if this is necessary but just in case



      var xmlData = new XML();
      xmlData.ignoreWhite = true;

      xmlData.onLoad = function () {
        //all the quiz script is here



      and for the button simply...


      on (press, release) {

      gotoAndPlay("quiz", 1);


        • 1. Re: How to load different xml files when required
          Ned Murphy Adobe Community Professional & MVP

          Your code for another category should look very much like the code you show for the first.  What problem are you having writing it?

          • 2. Re: How to load different xml files when required
            razzledee Level 1

            Thanks for your quick reply.


            Basically I don't know how to tell it to load the appropriate xml. Do I duplicate the quiz scene and give it a diiferent name eg quiz2 and direct the button code to go that scene but replacing the xml file with 2ndcategory.xml? I tried this and it didn't work. It loaded the questions and answers ok but instead of at the end of the set of questions going to the results it went straight to playing the second quiz scene.


            Surely doing the above even if it did work is not ideal as the quiz layout and actions are exactly the same... only the questions are from a different file.


            So there's the problem. How to get the second button to load the second xml and so on for the other categories. Do I code this on the button script or within the quiz script? Or both? And what would that code be?

            • 3. Re: How to load different xml files when required
              Ned Murphy Adobe Community Professional & MVP

              You seem to be overthinking this.  If you have a set of selections, then each selection should dictate what gets processed.


              What might work for you is to get out a pencil and paper and draw out a logic flow diagram for how your program should work.  Invlude whatever controls and sections you intend to have, and as you go you will probably find where you might not need some and maybe need others.

              • 4. Re: How to load different xml files when required
                razzledee Level 1

                How am I over thinking it? I have sets of questions each within categories. I want to load the questions that are appropriate to the category. A simple question!! I can get one xml file to load but I cannot get others to load when the corresponding categeories are selected. How is this over-thinking?


                So click on geography it loads the quiz with questions from geography xml.


                The quiz is set up to go to the results page after 10 questions. On the results page one can play the same category again or back to the menu and choose another. This time a player may choose science so it starts the quiz using questions from science xml.


                So I ask again.... how to get different xml files to load that uses the same quiz scene which contains the actionscript that populates the data from the xml files??


                Is there anyone else who may be able to help answer my original question?

                • 5. Re: How to load different xml files when required
                  Rothrock Level 5

                  All you have to do to load an xml is




                  It looks like you don't have the XML loading as part of a function. And it also looks like you are using a really old style of coding. The on (event) handler way of coding is going to make your project a lot more difficult than it needs to be.


                  Don't forget that loading the XML takes time. So you probably shouldn't start the quiz until after the file is loaded.


                  You need to add some code to your button clicks that tells the file to load the specific file you want.


                  Then inside your onLoad handler you should process the xml and then have it send the main timeline to the quiz bit.

                  • 6. Re: How to load different xml files when required
                    moccamaximum Level 5

                    as Ned and Rothrock already pointed out, its as simple as changing some parts of your button and load code.


                    the science button would have sth like this:


                    on (press, release) {




                    the palaeontology


                    on (press, release) {




                    and in your


                    xmlData.onLoad = function () {

                      gotoAndPlay("quiz", 1);

                      //all the quiz script is here