25 Replies Latest reply on Jan 24, 2010 7:20 AM by kglad

    Import XML data

    d0brin Level 1

      Can you tell me how to import form a single xml file, data to multiply text fields. if you can, tell me what is the AS code that imports the xml file in flash, than how to link the different txt fields to the difarent modules from the xml and what is the xml structure.

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

          we can give you a lot of information but noone can tell you your xml's structure.  that's for you to determine.  or, you could get help making that decision if you specify what data will be in the xml file.

          • 2. Re: Import XML data
            d0brin Level 1

            well just make it as an example with few categories and the as to import the data from each category to diferent text fields and i will figure it out

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

              your a.s.:

               

              var tl:MovieClip=this;
              var xml:XML=new XML();
              xml.ignoreWhite = true;
              xml.onLoad = parseXML;
              xml.load("text.xml");

               

              function parseXML(){
              for(var i:Number=0;i<this.firstChild.childNodes.length;i++){
              tl["tf"+(i+1)].text=this.firstChild.childNodes[i].firstChild.nodeValue;  // where tf1 and tf2 are your textfields
              }
              }

               

               

              your xml:

               

              <xml>
              <textfieldtext>text for tf1</textfieldtext>
              <textfieldtext>text for tf2</textfieldtext>
              </xml>

              • 4. Re: Import XML data
                d0brin Level 1

                and how you define which category form the xml file response to a certain text field?

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

                  the first node corresponds to the first textfield etc as indicated by the text in the xml.

                  • 6. Re: Import XML data
                    d0brin Level 1

                    and if i need to add to this AS and XML code a new category for the text field named container...how it would be?

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

                      you don't need to change any a.s. as long as you have enough textfields defined:

                       

                      <xml>
                      <textfieldtext>text for tf1</textfieldtext>
                      <textfieldtext>text for tf2</textfieldtext>

                      <textfieldtext>text for tf3</textfieldtext>
                      <textfieldtext>text for tf4</textfieldtext>

                      <textfieldtext>text for tf5</textfieldtext>
                      <textfieldtext>text for tf6</textfieldtext>
                      </xml>

                      • 8. Re: Import XML data
                        d0brin Level 1

                        but where i need to place the AS code when my text fields are in movie clips, should this code be on the main scene cuz it doesn't work :X And how to make the text selectable?

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

                          what are the path/names for your textfields?

                          • 10. Re: Import XML data
                            d0brin Level 1

                            well they are spread all over the website how i can define every single one of them?

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

                              every textfield that you want to reference using actionscript will need a path/name that's known to you.  flash will assign each unnamed object an instance name but that can be pretty tough to organize because they all have names like instance22 and instance59.

                              • 12. Re: Import XML data
                                d0brin Level 1

                                where to define the path?

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

                                  the path is determined by assigning instance names to the movieclips that contain your textfields.  so, if a textfield is on a timeline, you assign the textfield an instance name in the properties panel.  then you assign an instance name to the parent movieclip that contains that timeline etc until you reach the main timeline.

                                  • 14. Re: Import XML data
                                    d0brin Level 1

                                    aha and the name is the same tf1? for reaching tf1?

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

                                      if you have a textfield with instance name tf1 on the timeline that contains that code, tf1 is all that's needed to reference that textfield from that timeline.

                                       

                                      if you have a movieclip with instance name p on the timeline that contains that code and p has a movieclip with instance name c on its timeline and c has a textfield named tf1 on its timeline, p.c.tf1 would be needed to reference that textfield from the timeline that has the code.

                                      • 16. Re: Import XML data
                                        d0brin Level 1

                                        so i place this  p.c.tf1 as an instnace name of the text field that is conitaned in the c mc and the c mc is in the p mc or i have to put it as AS code?

                                         

                                        And one more thing how to make with what AS code and XMl syntax, to make from 2 foldiers thumbs and photos a thumb to be loaded on designated mc and a photo to be loaded on an other mc and a text to be shown from the XML file? It slike a gallerie with thumbs and photos and text how to make that?

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

                                          no.

                                           

                                          on the main timeline, click on that parent and in the properites panel assign the name p.  on p's timeline, click on that child movieclip and in the properites panel assign the name c.  on c's timeline, click on that textfield and in the properties panel assign the name tf.

                                           

                                          finally, you need to start learning flash and return here for questions about problems you're having.  if you want this done for you, you should send me an email via kglad.com to hire me.

                                          • 18. Re: Import XML data
                                            d0brin Level 1

                                            aha ok and btw i dont get that

                                             

                                            on the main timeline, click on that parent and in the properites panel assign the name p.  on p's timeline, click on that child movieclip and in the properites panel assign the name c.  on c's timeline, click on that textfield and in the properties panel assign the name tf.

                                             

                                            what do you mean like from the properties panel i give the instance name? or you mean something else? l

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

                                              do you know what the "properties panel" is?  (click window/properties.)

                                              • 20. Re: Import XML data
                                                d0brin Level 1

                                                i know the panel ... but what i don't understand is where i type this p.c.tf1 thing... on a frame label or mc instance name or var?

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

                                                  on the main timeline, click on that parent and in the properites panel assign the name p.  on p's timeline, click on that child movieclip and in the properites panel assign the name c.  on c's timeline, click on that textfield and in the properties panel assign the name tf1.

                                                   

                                                  you can then use p.c.tf1 to reference that textfield using code on the main timeline.

                                                  • 22. Re: Import XML data
                                                    d0brin Level 1

                                                    yes but what is that code that is what i am trying to find out

                                                    • 23. Re: Import XML data
                                                      kglad Adobe Community Professional & MVP

                                                      if you want to assign text to p.c.tf1, you can type the following in the actions panel:

                                                       

                                                      p.c.tf1.text="this is tf1 text";

                                                       

                                                      if you have textfields tf1,...,tf10 in p.c., you can use:

                                                       

                                                       

                                                      p.c["tf"+i].text = ...

                                                       

                                                      // instead of tl["tf"+i].text that i suggested in an above message.

                                                      • 24. Re: Import XML data
                                                        d0brin Level 1

                                                        ok thx

                                                        • 25. Re: Import XML data
                                                          kglad Adobe Community Professional & MVP

                                                          you're welcome.