22 Replies Latest reply on Feb 9, 2010 8:39 AM by d0brin

    XML Help

    d0brin Level 1

      So i will try to explain it as i can . So I have this flash game. In it there is one movie clip called address_group. In address_group i have another MC called address. In address i have many text fields. Their info is being loaded from a xml file called database.xml. In the timeline where my address_group MC is located i have placed this code to load the XML data to flash:

       

      var planet_title = new Array();

      var planet_subtitle = new Array();

      var chevron1_txt = new Array();

      var chevron2_txt = new Array();

      var chevron3_txt = new Array();

      var chevron4_txt = new Array();

      var chevron5_txt = new Array();

      var chevron6_txt = new Array();

      var chevron7_txt = new Array();

      var chevron8_txt = new Array();

      var symbol_1 = new Array();

      var symbol_2 = new Array();

      var symbol_3 = new Array();

      var symbol_4 = new Array();

      var symbol_5 = new Array();

      var symbol_6 = new Array();

      var symbol_7 = new Array();

      var symbol_8 = new Array();

      var planet_stats = new Array();

      var planet_id = new Array();

      var pln_location = new Array();

      var pln_atmos = new Array();

      var pln_weather = new Array();

      var pln_day = new Array();

      var pln_inhabited = new Array();


      var database = new XML();

      database.ignoreWhite = true;

      database.load("database.xml");

      dir = address_group.address

      database.onLoad = function()

      {

      var nodes:Array = this.firstChild.childNodes;

      for(var i=0;i<nodes.length;i++)

      {

      planet_title.push(nodes[i].attributes.title_planet);

      planet_subtitle.push(nodes[i].attributes.subtitle);

      chevron1_txt.push(nodes[i].attributes.chevron1_name);

      chevron2_txt.push(nodes[i].attributes.chevron2_name);

      chevron3_txt.push(nodes[i].attributes.chevron3_name);

      chevron4_txt.push(nodes[i].attributes.chevron4_name);

      chevron5_txt.push(nodes[i].attributes.chevron5_name);

      chevron6_txt.push(nodes[i].attributes.chevron6_name);

      chevron7_txt.push(nodes[i].attributes.chevron7_name);

      chevron8_txt.push(nodes[i].attributes.chevron8_name);

      symbol_1.push(nodes[i].attributes.symbol1_name);

      symbol_2.push(nodes[i].attributes.symbol2_name);

      symbol_3.push(nodes[i].attributes.symbol3_name);

      symbol_4.push(nodes[i].attributes.symbol4_name);

      symbol_5.push(nodes[i].attributes.symbol5_name);

      symbol_6.push(nodes[i].attributes.symbol6_name);

      symbol_7.push(nodes[i].attributes.symbol7_name);

      symbol_8.push(nodes[i].attributes.symbol8_name);

      planet_stats.push(nodes[i].attributes.planet_status);

      planet_id.push(nodes[i].attributes.ID);

      pln_location.push(nodes[i].attributes.pln_cuadrant);

      pln_atmos.push(nodes[i].attributes.planet_atmosphere);

      pln_weather.push(nodes[i].attributes.planet_weather);

      pln_day.push(nodes[i].attributes.planet_day_cycle);

      pln_inhabited.push(nodes[i].attributes.planet_inhabited);

       

      dir.title.text = planet_title;

      dir.sub_title.text = planet_subtitle;

      dir.chev1_name.text = chevron1_txt;

      dir.chev2_name.text = chevron2_txt;

      dir.chev3_name.text = chevron3_txt;

      dir.chev4_name.text = chevron4_txt;

      dir.chev5_name.text = chevron5_txt;

      dir.chev6_name.text = chevron6_txt;

      dir.chev7_name.text = chevron7_txt;

      dir.chev8_name.text = chevron8_txt;

      dir.SB1.text = symbol_1;

      dir.SB2.text = symbol_2;

      dir.SB3.text = symbol_3;

      dir.SB4.text = symbol_4;

      dir.SB5.text = symbol_5;

      dir.SB6.text = symbol_6;

      dir.SB7.text = symbol_7;

      dir.SB8.text = symbol_8;

      dir.planet_status.text = planet_stats;

      dir.planet_id.text = planet_id;

      dir.location.text = pln_location;

      dir.weather.text = pln_weather;

      dir.day_cycle.text = pln_day;

      dir.inhabited.text = pln_inhabited;

      }

      }

       

      My xml file structure is this:

       

      <?xml version="1.0" encoding="utf-8"?>

      <planets>

      <planet title_planet="Lqlq"

      subtitle="M45-98R"

      chevron1_name="Asus"

      chevron2_name="Asus"

      chevron3_name="Asus"

      chevron4_name="Asus"

      chevron5_name="Asus"

      chevron6_name="Asus"

      chevron7_name="Asus"

      chevron8_name="Asus"

      symbol1_name="d"

      symbol2_name="d"

      symbol3_name="d"

      symbol4_name="d"

      symbol5_name="d"

      symbol6_name="d"

      symbol7_name="d"

      symbol8_name="d"

      planet_status="ACTIVE"

      ID="#653265"

      pln_cuadrant="C8 Cuadrant"

      planet_atmosphere="YES"

      planet_weather="NORMAL"

      planet_day_cycle="24 hrs"

      planet_inhabited="NO" />

      <planet title_planet="Lqlq"

      subtitle="M45-98R"

      chevron1_name="Asus"

      chevron2_name="Asus"

      chevron3_name="Asus"

      chevron4_name="Asus"

      chevron5_name="Asus"

      chevron6_name="Asus"

      chevron7_name="Asus"

      chevron8_name="Asus"

      symbol1_name="d"

      symbol2_name="d"

      symbol3_name="d"

      symbol4_name="d"

      symbol5_name="d"

      symbol6_name="d"

      symbol7_name="d"

      symbol8_name="d"

      planet_status="ACTIVE"

      ID="#653265"

      pln_cuadrant="C8 Cuadrant"

      planet_atmosphere="YES"

      planet_weather="NORMAL"

      planet_day_cycle="24 hrs"

      planet_inhabited="NO" />

      </planets>

       

      My problem is that when there is a second <planet title_planet="Name"....> the new info from the second input which should be a new entry which means that i want when there is a second input this address_group to duplicate and in it to be placed the info from the second entry. But it doesnt do that it loads the second info over the first one in the flash. So my question is how to make flash to detect if there is something written as second entry or third or forth and so on... and than when he detects to duplicate this address_group Movie Clip and in it to put the info from the second enttry if they are 3 to make 3 copies of the MC and put in each the different informations....

       

      Did you understand what i mean please help? thanks a lot

        • 1. Re: XML Help
          kglad Adobe Community Professional & MVP

          assign address_group a class (say Address_Group), remove the current address_group from the main stage and use:

           


           

          var planet_title = new Array();

          var planet_subtitle = new Array();

          var chevron1_txt = new Array();

          var chevron2_txt = new Array();

          var chevron3_txt = new Array();

          var chevron4_txt = new Array();

          var chevron5_txt = new Array();

          var chevron6_txt = new Array();

          var chevron7_txt = new Array();

          var chevron8_txt = new Array();

          var symbol_1 = new Array();

          var symbol_2 = new Array();

          var symbol_3 = new Array();

          var symbol_4 = new Array();

          var symbol_5 = new Array();

          var symbol_6 = new Array();

          var symbol_7 = new Array();

          var symbol_8 = new Array();

          var planet_stats = new Array();

          var planet_id = new Array();

          var pln_location = new Array();

          var pln_atmos = new Array();

          var pln_weather = new Array();

          var pln_day = new Array();

          var pln_inhabited = new Array();


          var database = new XML();

          database.ignoreWhite = true;

          database.load("database.xml");


          database.onLoad = function()

          {

          var nodes:Array = this.firstChild.childNodes;

          for(var i=0;i<nodes.length;i++)

          {

          var address_group:Address_Group = new Address_Group();

          addChild(address_group);

          // assign x,y and any other properties needed for display

          var dir:MovieClip = address_group.address;

          planet_title.push(nodes[i].attributes.title_planet);

          planet_subtitle.push(nodes[i].attributes.subtitle);

          chevron1_txt.push(nodes[i].attributes.chevron1_name);

          chevron2_txt.push(nodes[i].attributes.chevron2_name);

          chevron3_txt.push(nodes[i].attributes.chevron3_name);

          chevron4_txt.push(nodes[i].attributes.chevron4_name);

          chevron5_txt.push(nodes[i].attributes.chevron5_name);

          chevron6_txt.push(nodes[i].attributes.chevron6_name);

          chevron7_txt.push(nodes[i].attributes.chevron7_name);

          chevron8_txt.push(nodes[i].attributes.chevron8_name);

          symbol_1.push(nodes[i].attributes.symbol1_name);

          symbol_2.push(nodes[i].attributes.symbol2_name);

          symbol_3.push(nodes[i].attributes.symbol3_name);

          symbol_4.push(nodes[i].attributes.symbol4_name);

          symbol_5.push(nodes[i].attributes.symbol5_name);

          symbol_6.push(nodes[i].attributes.symbol6_name);

          symbol_7.push(nodes[i].attributes.symbol7_name);

          symbol_8.push(nodes[i].attributes.symbol8_name);

          planet_stats.push(nodes[i].attributes.planet_status);

          planet_id.push(nodes[i].attributes.ID);

          pln_location.push(nodes[i].attributes.pln_cuadrant);

          pln_atmos.push(nodes[i].attributes.planet_atmosphere);

          pln_weather.push(nodes[i].attributes.planet_weather);

          pln_day.push(nodes[i].attributes.planet_day_cycle);

          pln_inhabited.push(nodes[i].attributes.planet_inhabited);

           

          dir.title.text = planet_title;

          dir.sub_title.text = planet_subtitle;

          dir.chev1_name.text = chevron1_txt;

          dir.chev2_name.text = chevron2_txt;

          dir.chev3_name.text = chevron3_txt;

          dir.chev4_name.text = chevron4_txt;

          dir.chev5_name.text = chevron5_txt;

          dir.chev6_name.text = chevron6_txt;

          dir.chev7_name.text = chevron7_txt;

          dir.chev8_name.text = chevron8_txt;

          dir.SB1.text = symbol_1;

          dir.SB2.text = symbol_2;

          dir.SB3.text = symbol_3;

          dir.SB4.text = symbol_4;

          dir.SB5.text = symbol_5;

          dir.SB6.text = symbol_6;

          dir.SB7.text = symbol_7;

          dir.SB8.text = symbol_8;

          dir.planet_status.text = planet_stats;

          dir.planet_id.text = planet_id;

          dir.location.text = pln_location;

          dir.weather.text = pln_weather;

          dir.day_cycle.text = pln_day;

          dir.inhabited.text = pln_inhabited;

          }

          }

           

          My xml file structure is this:

           

           

          <?xml version="1.0" encoding="utf-8"?>

          <planets>

          <planet title_planet="Lqlq"

          subtitle="M45-98R"

          chevron1_name="Asus"

          chevron2_name="Asus"

          chevron3_name="Asus"

          chevron4_name="Asus"

          chevron5_name="Asus"

          chevron6_name="Asus"

          chevron7_name="Asus"

          chevron8_name="Asus"

          symbol1_name="d"

          symbol2_name="d"

          symbol3_name="d"

          symbol4_name="d"

          symbol5_name="d"

          symbol6_name="d"

          symbol7_name="d"

          symbol8_name="d"

          planet_status="ACTIVE"

          ID="#653265"

          pln_cuadrant="C8 Cuadrant"

          planet_atmosphere="YES"

          planet_weather="NORMAL"

          planet_day_cycle="24 hrs"

          planet_inhabited="NO" />

          <planet title_planet="Lqlq"

          subtitle="M45-98R"

          chevron1_name="Asus"

          chevron2_name="Asus"

          chevron3_name="Asus"

          chevron4_name="Asus"

          chevron5_name="Asus"

          chevron6_name="Asus"

          chevron7_name="Asus"

          chevron8_name="Asus"

          symbol1_name="d"

          symbol2_name="d"

          symbol3_name="d"

          symbol4_name="d"

          symbol5_name="d"

          symbol6_name="d"

          symbol7_name="d"

          symbol8_name="d"

          planet_status="ACTIVE"

          ID="#653265"

          pln_cuadrant="C8 Cuadrant"

          planet_atmosphere="YES"

          planet_weather="NORMAL"

          planet_day_cycle="24 hrs"

          planet_inhabited="NO" />

          </planets>

          • 2. Re: XML Help
            d0brin Level 1

            yeah thanks that loks very nice but i dont completely understand the thing with the calsses? can you help me on that. How to create a new one nad is it liek an external as file or... and what to put in it if it is?

            • 3. Re: XML Help
              kglad Adobe Community Professional & MVP

              in your library, right click on the address_group movieclip, click linkage, tick export of actionscript and assign that class.  that's all you need to do, in addition, to using the code i showed above.

              • 4. Re: XML Help
                d0brin Level 1

                Yeha but it say after i do what you said:

                 

                The class or interface 'Address_Group' could not be loaded. I am attaching my files to see what is happening....

                • 5. Re: XML Help
                  kglad Adobe Community Professional & MVP

                  sorry.  that would only work for as3.

                   

                  for as2, assign address_group a linkage id (say address_groupID), and use:

                   


                   

                  var planet_title = new Array();

                  var planet_subtitle = new Array();

                  var chevron1_txt = new Array();

                  var chevron2_txt = new Array();

                  var chevron3_txt = new Array();

                  var chevron4_txt = new Array();

                  var chevron5_txt = new Array();

                  var chevron6_txt = new Array();

                  var chevron7_txt = new Array();

                  var chevron8_txt = new Array();

                  var symbol_1 = new Array();

                  var symbol_2 = new Array();

                  var symbol_3 = new Array();

                  var symbol_4 = new Array();

                  var symbol_5 = new Array();

                  var symbol_6 = new Array();

                  var symbol_7 = new Array();

                  var symbol_8 = new Array();

                  var planet_stats = new Array();

                  var planet_id = new Array();

                  var pln_location = new Array();

                  var pln_atmos = new Array();

                  var pln_weather = new Array();

                  var pln_day = new Array();

                  var pln_inhabited = new Array();


                  var database = new XML();

                  database.ignoreWhite = true;

                  database.load("database.xml");

                  var tl:MovieClip=this;


                  database.onLoad = function()

                  {

                  var nodes:Array = this.firstChild.childNodes;

                  for(var i=0;i<nodes.length;i++)

                  {

                  var address_group:MovieClip = tl.attachMovie("attach_groupID","attach_groupMC_"+i,tl.getNextHighestDepth());

                  address_group._ x= i*100;

                  // assign x,y and any other properties needed for display

                  var dir:MovieClip = address_group.address;

                  planet_title.push(nodes[i].attributes.title_planet);

                  planet_subtitle.push(nodes[i].attributes.subtitle);

                  chevron1_txt.push(nodes[i].attributes.chevron1_name);

                  chevron2_txt.push(nodes[i].attributes.chevron2_name);

                  chevron3_txt.push(nodes[i].attributes.chevron3_name);

                  chevron4_txt.push(nodes[i].attributes.chevron4_name);

                  chevron5_txt.push(nodes[i].attributes.chevron5_name);

                  chevron6_txt.push(nodes[i].attributes.chevron6_name);

                  chevron7_txt.push(nodes[i].attributes.chevron7_name);

                  chevron8_txt.push(nodes[i].attributes.chevron8_name);

                  symbol_1.push(nodes[i].attributes.symbol1_name);

                  symbol_2.push(nodes[i].attributes.symbol2_name);

                  symbol_3.push(nodes[i].attributes.symbol3_name);

                  symbol_4.push(nodes[i].attributes.symbol4_name);

                  symbol_5.push(nodes[i].attributes.symbol5_name);

                  symbol_6.push(nodes[i].attributes.symbol6_name);

                  symbol_7.push(nodes[i].attributes.symbol7_name);

                  symbol_8.push(nodes[i].attributes.symbol8_name);

                  planet_stats.push(nodes[i].attributes.planet_status);

                  planet_id.push(nodes[i].attributes.ID);

                  pln_location.push(nodes[i].attributes.pln_cuadrant);

                  pln_atmos.push(nodes[i].attributes.planet_atmosphere);

                  pln_weather.push(nodes[i].attributes.planet_weather);

                  pln_day.push(nodes[i].attributes.planet_day_cycle);

                  pln_inhabited.push(nodes[i].attributes.planet_inhabited);

                   

                  dir.title.text = planet_title;

                  dir.sub_title.text = planet_subtitle;

                  dir.chev1_name.text = chevron1_txt;

                  dir.chev2_name.text = chevron2_txt;

                  dir.chev3_name.text = chevron3_txt;

                  dir.chev4_name.text = chevron4_txt;

                  dir.chev5_name.text = chevron5_txt;

                  dir.chev6_name.text = chevron6_txt;

                  dir.chev7_name.text = chevron7_txt;

                  dir.chev8_name.text = chevron8_txt;

                  dir.SB1.text = symbol_1;

                  dir.SB2.text = symbol_2;

                  dir.SB3.text = symbol_3;

                  dir.SB4.text = symbol_4;

                  dir.SB5.text = symbol_5;

                  dir.SB6.text = symbol_6;

                  dir.SB7.text = symbol_7;

                  dir.SB8.text = symbol_8;

                  dir.planet_status.text = planet_stats;

                  dir.planet_id.text = planet_id;

                  dir.location.text = pln_location;

                  dir.weather.text = pln_weather;

                  dir.day_cycle.text = pln_day;

                  dir.inhabited.text = pln_inhabited;

                  }

                  }

                   

                  My xml file structure is this:

                   

                   

                  <?xml version="1.0" encoding="utf-8"?>

                  <planets>

                  <planet title_planet="Lqlq"

                  subtitle="M45-98R"

                  chevron1_name="Asus"

                  chevron2_name="Asus"

                  chevron3_name="Asus"

                  chevron4_name="Asus"

                  chevron5_name="Asus"

                  chevron6_name="Asus"

                  chevron7_name="Asus"

                  chevron8_name="Asus"

                  symbol1_name="d"

                  symbol2_name="d"

                  symbol3_name="d"

                  symbol4_name="d"

                  symbol5_name="d"

                  symbol6_name="d"

                  symbol7_name="d"

                  symbol8_name="d"

                  planet_status="ACTIVE"

                  ID="#653265"

                  pln_cuadrant="C8 Cuadrant"

                  planet_atmosphere="YES"

                  planet_weather="NORMAL"

                  planet_day_cycle="24 hrs"

                  planet_inhabited="NO" />

                  <planet title_planet="Lqlq"

                  subtitle="M45-98R"

                  chevron1_name="Asus"

                  chevron2_name="Asus"

                  chevron3_name="Asus"

                  chevron4_name="Asus"

                  chevron5_name="Asus"

                  chevron6_name="Asus"

                  chevron7_name="Asus"

                  chevron8_name="Asus"

                  symbol1_name="d"

                  symbol2_name="d"

                  symbol3_name="d"

                  symbol4_name="d"

                  symbol5_name="d"

                  symbol6_name="d"

                  symbol7_name="d"

                  symbol8_name="d"

                  planet_status="ACTIVE"

                  ID="#653265"

                  pln_cuadrant="C8 Cuadrant"

                  planet_atmosphere="YES"

                  planet_weather="NORMAL"

                  planet_day_cycle="24 hrs"

                  planet_inhabited="NO" />

                  </planets>

                  p.s.  you assign a linkage id the same way you assign a class.  so, just remove the input from the class textfield and enter the linkage id in the linkage textfield.

                  • 6. Re: XML Help
                    d0brin Level 1

                    aha but now it says for this:

                     

                    ...code...

                     

                    {

                    var nodes:Array = this.firstChild.childNodes;

                    for(var i=0;i<nodes.length;i++)

                    {

                    var address_group:MovieClip = tl.attachMovie("attach_groupID","attach_groupMC_"+i,tl.getNextHighestDepth());

                            address_group._ x= i*100;

                            // assign x,y and any other properties needed for display

                            var dir:MovieClip = address_group.address;

                    ...code...

                     

                     

                    it says: Syntax error.

                     

                    any idea?

                    • 7. Re: XML Help
                      kglad Adobe Community Professional & MVP

                      click file/publish settings/flash and tick "permit debugging".  the line with the error will be mentioned in the error message.  copy and paste the complete error message and indicate that line of code.

                      • 8. Re: XML Help
                        d0brin Level 1

                        Here it is the complete error message:

                         

                        error_msg.JPG

                        • 9. Re: XML Help
                          kglad Adobe Community Professional & MVP

                          you have a space between the underscore and x.  remove it.

                          • 10. Re: XML Help
                            d0brin Level 1

                            oh thanks one more thing...now it shows normal i mean last time the two entries in the XML were overlapping on one space in flash, now its ok. The entry for the first planet is showing normal on its place but in the XML i have second one, and i dont see it. Maybe because i dont have anything assigned for y properties need for display? If so.. can you tell me how to write this display properties for the Y axis. I want the different entries to show one under another with somewhere around 10px distance between them.

                            • 11. Re: XML Help
                              kglad Adobe Community Professional & MVP

                              where you're currently assigning a _x value (and where you had a problem), use:

                               

                              address_group._y = i*10;

                               

                              p.s.  please mark this thread as answered, if your issue is resolved.

                              • 12. Re: XML Help
                                d0brin Level 1

                                okey something doesnt work could you please take a look at the file and tell me whats wrong :X

                                 

                                P.S the content is on frame 2 i did everything and still something is happening...

                                • 13. Re: XML Help
                                  kglad Adobe Community Professional & MVP

                                  you'll need to save your fla for as3.

                                  • 14. Re: XML Help
                                    d0brin Level 1

                                    oh right sorry forgot that you use cs3 adn btw now when i saved it as cs3 ( i made the a copy of the file) flash says that the XML metadata will be lost and now i dont see the XML text imputs as it was when the file was in cs4...but here i attach it...please help me

                                    • 15. Re: XML Help
                                      kglad Adobe Community Professional & MVP

                                      that's still saved for cs4.

                                       

                                      i'll check your files in a few hours when i have access to flash cs4.

                                      • 16. Re: XML Help
                                        d0brin Level 1

                                        oks thanks a lot but check the file from my previuse post cuz this one may somehome i mixed up the files

                                        • 17. Re: XML Help
                                          kglad Adobe Community Professional & MVP

                                          both files were cs4 files.

                                          • 18. Re: XML Help
                                            d0brin Level 1

                                            can you check it as cs4 because there is some problems when i save the file in CS3 format it says that the XML meta data will be lost :X  and

                                            • 19. Re: XML Help
                                              kglad Adobe Community Professional & MVP

                                              i generally don't download and correct files unless i'm hired.   but, i did download and look at your file long enough to remind me why i usually don't download and correct files:  it's too time-consuming to find where all your code is located.

                                              • 20. Re: XML Help
                                                d0brin Level 1

                                                oh sry it is located at

                                                 

                                                Frame 2 -> container_mc (Layer: Content) -> content_ms -> (Layer: Actions)

                                                 

                                                This is where my code it is and its referring for the text fields in the movie clip named: tn_group -> Ad 1

                                                 

                                                There is located my code

                                                • 21. Re: XML Help
                                                  kglad Adobe Community Professional & MVP

                                                  this is the first time i've posted the below text in an adobe forum.  i send this text to people that send me private messages and emails asking for help but, i think it's appropriate here:

                                                   

                                                  i earn part of my living helping clients with flash and related programming issues.  if you want to hire me to help, please send me an email via my website:  http://www.kglad.com

                                                   

                                                  in addition, to my flash-for-pay work i donate considerable time and effort to the flash community by trying to help people that post on the 3 main (as1/as2, as3, flash) adobe flash forums.  if you want free help, post your issue to the appropriate forum.  if i am able and interested in your issue, i will probably respond.  and, if i don't, someone else probably will.

                                                   

                                                  if you state your issue clearly, and especially if you pinpoint the problem, you almost certainly will be helped free of charge.  if you have a complex problem and especially if you require source (fla and/or as) files to be corrected, you almost certainly should consider hiring someone to help.  again, you can hire me via my website.

                                                   

                                                  thank you for understanding,

                                                   

                                                  kglad
                                                  Flash Consulting Services
                                                  www.kglad.co

                                                  • 22. Re: XML Help
                                                    d0brin Level 1

                                                    oks thank you