25 Replies Latest reply on Aug 27, 2011 7:23 AM by kglad

    Problem to load XML

    melas076 Level 1

      dear,

       

      i have problem to load a xml file from flash.

       

      see in below:

       

      when i put this : xmlpath.load(_root.xmlFile==undefined?"datas.xml":_root.xmlFile);  it works perfect in flash but not in the browser.

       

      kindly help me on this...

       

      i will appreciate your help

       

      regards,

      MELAS076

        • 1. Re: Problem to load XML
          kglad Adobe Community Professional & MVP

          what's your url and what needs to be done (if anything) to show the problem?


          1 person found this helpful
          • 2. Re: Problem to load XML
            melas076 Level 1

            I solved the URL But i have some issues between 2 flashs and 2 xml files which they are loading and navigate together....

             

            let me explain my problem is:

             

            - i have 2 flashs (main + index) and 2 xmls(data + datas) but they are not in the same path.

            in the main.swf : we have pictures of product which is load datas from data.xml and it is loading MC when clicked on one of picture.

            is in the root path.

            in the index.swf: we have all details and pictures of product which is loaded from datas.xml clicked by main.swf

            is in the root path/products/name1/ and we have root path/products/name2/.

             

            and each product has datas.xml in their folder with index.swf

             

            so how can i let the index.swf load its datas.xml when i clicked from main.swf?

             

            My main.swf code:

             

            stop();

            function loadXML(loaded) {

             

            if (loaded) {

             

            xmlNode = this.firstChild;
            links = [];
            description = [];
            thumbnails = [];
            a =[];
            total = xmlNode.firstChild.childNodes.length;
            for (i=0; i<total; i++) {

             

            links[i] = xmlNode.firstChild.childNodes[i].attributes.datas;
            description[i] = xmlNode.firstChild.childNodes[i].attributes.label;
            thumbnails[i] = xmlNode.firstChild.childNodes[i].attributes.thumbs;
            a[i] = xmlNode.firstChild.childNodes[i].attributes.folder;
            thumbnails_fn(i);
            //trace(xmlNode.firstChild.childNodes[1].attributes.thumbs);

             

            initPreloading();
            }
            //firstImage();

             

            } else {

             

            content = "file not loaded!";

             

            }
            }

             

            xmlData = new XML();
            xmlData.ignoreWhite = true;
            xmlData.onLoad = loadXML;
            xmlData.load("data.xml");

             

            p = 0;
             
            function thumbnails_fn(k) {

             

            this.thumbnail_mc.createEmptyMovieClip("t"+k, this.thumbnail_mc.getNextHighestDepth());
            tlistener = new Object();
            tlistener.onLoadInit = function(target_mc) {

             

            target_mc._x = (eval("this.thumbnail_mc.t"+k)._width+20)*k;
            target_mc.pictureValue = k;
            aa = xmlData.firstChild.firstChild.childNodes[k].attributes.datas;
            target_mc.onRelease = function() {

             

            LOADmc.loadMovie(aa);

             

            //trace();
            p = this.pictureValue;
            //nextImage();

             

            };
            target_mc.onRollOver = function() {

             

            this._alpha = 90;
            //thumbNailScroller();

             

            };
            target_mc.onRollOut = function() {

             

            this._alpha = 100;

             

            };

             

            };
            image_mcl = new MovieClipLoader();
            image_mcl.addListener(tlistener);
            image_mcl.loadClip(thumbnails[k], "thumbnail_mc.t"+k);

             

            }
            LOADmc._x=(alignmc.width-LOADmc._width)/2;
            LOADmc._y=(alignmc.height-LOADmc._height)/2;

             

            -----------------------------------------------------------------------------------

            my data.xml:


            <?xml version="1.0"?>
            <data>
              <category title="OUR PRODUCTS">
                <item id="1" folder="Products/Multihost" thumbs="Products/Multihost/thumbs/1.jpg" label="Multihost" datas="Products/Multihost/index.swf"/>
                <item id="2" folder="Products/VOIP" thumbs="Products/VOIP/thumbs/image1.jpg" label="VO IP" datas="Products/VOIP/index.swf"/>
              </category>
            </data>

            -----------------------------------------------------------------------------

            my index.swf in each product/name :

             

            var xmlfiles:XML = new XML();
            xmlfiles.ignoreWhite = true;
            xmlfiles.load("../../data.xml");
            xmlfiles.onLoad=function(success) {
                if (success) {
            //        total = xmlfiles.firstChild.firstChild.childNodes.length;
            //for (i=0; i<total; i++) {

             

                    var ba = xmlNodes.firstChild.firstChild.childNodes[k].attributes.folder;
                   
                }

             

             

             


            var xmlOb:XML = new XML();
            xmlOb.ignoreWhite = true;
            xmlOb.onLoad = function() {
               
                var aux:main = new main(xmlOb);
                }
                trace(ba+"/datas.xml");
            xmlOb.load(a+"/datas.xml");
            }
            //xmlOb.load(_root.xmlFile==undefined?"datas.xml":_root.xmlFile);
            //xmlOb.load("products/multihost/datas.xml");


            -------------------------------------------------------------------------------

            my datas.xml for prduct name 1:

             

            <?xml version="1.0" encoding="utf-8"?>
            <product>
              <gallery>
                <button id="1" title="Multihost 20" subtitle="MH20" thumb="Products/Multihost/thumbs/2.jpg" ProductTitle="MH20">
                  <picture thumb="Products/Multihost/thumbs/1.jpg" image="Products/Multihost/images/1.jpg"/>
                  <picture thumb="Products/Multihost/thumbs/2.jpg" image="Products/Multihost/images/2.jpg"/>
                  <picture thumb="Products/Multihost/thumbs/3.jpg" image="Products/Multihost/images/3.jpg"/>
                  <picture thumb="Products/Multihost/thumbs/5.jpg" image="Products/Multihost/images/5.jpg"/>
                  <description linkname="MH Overview.pdf"><![CDATA[Marwan salem tests]]></description>
                </button>
              </gallery>
              <mainTitle MainTitle="Multihost"/>
            </product>
            ---------------------------------------------------------------------------

            my datas.xml for prduct name 2:

            <?xml version="1.0" encoding="utf-8"?>
            <product>
              <gallery>
            <button id="0" title="VO IP 20" subtitle="VO IP 20" thumb="Products/VO IP/thumbs/image1.jpg" ProductTitle="VO IP 20"><picture thumb="Products/VO IP/thumbs/image1.jpg" image="Products/VO IP/images/image1.jpg"/><description linkname="Multi-Host Flyer.pdf"><![CDATA[MArwan VO IP 20]]></description></button></gallery>
              <mainTitle MainTitle="VO IP"/>
            </product>
            ------------------------------------------------------------------------------------------ ---------------

             

             

             

            thanks for your help.

             

            best regards,

             

            MELAS076

             

            Message was edited by: melas076

            • 3. Re: Problem to load XML
              kglad Adobe Community Professional & MVP

              if index.swf is loaded into main.swf, the path used by index.swf to load an xml file is relative to the location of main.swf's embedding html.

              1 person found this helpful
              • 4. Re: Problem to load XML
                melas076 Level 1

                Dear Kglad,

                 

                yes index.swf is loaded into main.swf. how is to be relative path?

                 

                but when i clicked on the 2nd product it is give me the datas.xml of the 1st product.

                 

                i hope that you understand.

                 

                thanks for your help.

                 

                best regards,

                MELAS076

                • 5. Re: Problem to load XML
                  kglad Adobe Community Professional & MVP

                  no, i don't understand you.

                  • 6. Re: Problem to load XML
                    melas076 Level 1

                    kindly check my code which i putted.


                    i meant that main.swf loads data.xml which 2 products are in. then when i clicked one of the products, it loads the index.swf and loads datas.xml.

                     

                    each product has datas.xml in their folder. normally, when i clicked on the "product 2", i have index.swf loaded and datas.xml of "product 2".

                    Now, it loads datas.xml of "product 1". How can i do it?

                     

                    kind regards,

                    MELAS076

                    • 7. Re: Problem to load XML
                      melas076 Level 1

                      any news please!!!

                       

                      i will appreciate your help!

                       

                      kind regards,

                      MELAS076

                      • 8. Re: Problem to load XML
                        kglad Adobe Community Professional & MVP

                        what directory is your main html in?

                         

                        what directory is your xml that needs to be loaded?

                        • 9. Re: Problem to load XML
                          melas076 Level 1

                          Dear,

                           

                          - the main.swf and main.html are in the root path C:/project/

                          - the index.swf and the datas.xml are in C:/project/products/product1/ and C:/project/products/product2/

                           

                          - in the future, we can add C:/project/products/product3/ so it willl recognize automatically....

                           

                          kind regards,

                          MELAS076

                          • 10. Re: Problem to load XML
                            kglad Adobe Community Professional & MVP

                            use:

                             

                             

                            var a:String="products/product1";

                            xmlOb.load(a+"/datas.xml");

                            1 person found this helpful
                            • 11. Re: Problem to load XML
                              melas076 Level 1

                              dear,

                               

                              It is working but when i click on the product2 from main.swf which it reads data.xml (you will find in the 2nd post in the up).

                              It gives me the product1....

                               

                              kind regards,

                              MELAS076

                              • 12. Re: Problem to load XML
                                kglad Adobe Community Professional & MVP

                                you need to use two different named xml files and load whichever one you want into main and which ever you want into index.

                                • 13. Re: Problem to load XML
                                  melas076 Level 1

                                  yes i have data.xml (main.swf) and datas.xml(index.swf) so i want take the attribute "folder" from data.xml and put in index.swf which i click on the product choosen.

                                   

                                  see in below:


                                  data.xml

                                   

                                  <?xml version="1.0"?>
                                  <data>
                                    <category title="OUR PRODUCTS">
                                      <item id="1" folder="Products/Multihost" thumbs="Products/Multihost/thumbs/1.jpg" label="Multihost" datas="Products/Multihost/index.swf"/>
                                      <item id="2" folder="Products/VOIP" thumbs="Products/VOIP/thumbs/image1.jpg" label="VO IP" datas="Products/VOIP/index.swf"/>
                                    </category>
                                  </data>

                                   

                                   

                                  datas.xml for product  1 "multihost"

                                   

                                  <?xml version="1.0" encoding="utf-8"?>
                                  <product>
                                    <gallery>
                                      <button id="1" title="Multihost 20" subtitle="MH20" thumb="Products/Multihost/thumbs/2.jpg" ProductTitle="MH20">
                                        <picture thumb="Products/Multihost/thumbs/1.jpg" image="Products/Multihost/images/1.jpg"/>
                                        <picture thumb="Products/Multihost/thumbs/2.jpg" image="Products/Multihost/images/2.jpg"/>
                                        <picture thumb="Products/Multihost/thumbs/3.jpg" image="Products/Multihost/images/3.jpg"/>
                                        <picture thumb="Products/Multihost/thumbs/5.jpg" image="Products/Multihost/images/5.jpg"/>
                                        <description linkname="MH Overview.pdf"><![CDATA[Marwan salem tests]]></description>
                                      </button>
                                    </gallery>
                                    <mainTitle MainTitle="Multihost"/>
                                  </product>

                                   

                                  datas.xml for product 2 "VO IP"

                                   

                                  <?xml version="1.0" encoding="utf-8"?>
                                  <product>
                                    <gallery>
                                  <button id="0" title="VO IP 20" subtitle="VO IP 20" thumb="Products/VO IP/thumbs/image1.jpg" ProductTitle="VO IP 20"><picture thumb="Products/VO IP/thumbs/image1.jpg" image="Products/VO IP/images/image1.jpg"/><description linkname="Multi-Host Flyer.pdf"><![CDATA[MArwan VO IP 20]]></description></button></gallery>
                                    <mainTitle MainTitle="VO IP"/>
                                  </product>

                                   

                                  kind regards,

                                  MELAS076

                                  • 14. Re: Problem to load XML
                                    kglad Adobe Community Professional & MVP

                                    you can't have two different files with the same name in the same directory.

                                    1 person found this helpful
                                    • 15. Re: Problem to load XML
                                      melas076 Level 1

                                      it is not on the same folders/directory.

                                      data.xml is in the c:/project/

                                      datas.xml are in the c:/project/products/multihost/ and c:/project/products/VOIP/

                                      • 16. Re: Problem to load XML
                                        kglad Adobe Community Professional & MVP

                                        when you want the one in multihost, use

                                         

                                        var a:String="products/multihost";

                                        xmlOb.load(a+"/datas.xml");

                                         

                                        and when you want the one in VOIP, use:

                                         

                                        var a:String="products/VOIP";

                                        xmlOb.load(a+"/datas.xml");

                                        • 17. Re: Problem to load XML
                                          melas076 Level 1

                                          i know that but i want to send theses path which are in data.xml "attribute.folder" throught 'main.swf' to index.swf. is it possible?

                                          • 18. Re: Problem to load XML
                                            kglad Adobe Community Professional & MVP

                                            yes, it's possible.

                                             

                                            how are you trying to do that now?

                                            • 19. Re: Problem to load XML
                                              melas076 Level 1

                                              yes, I tried and i am trying since this morning but i didn't find it.

                                              Please help me...

                                               

                                              kind regards,

                                              MELAS076

                                              • 20. Re: Problem to load XML
                                                melas076 Level 1

                                                Help me plz

                                                 

                                                kind regards,

                                                MELAS076

                                                • 21. Re: Problem to load XML
                                                  melas076 Level 1

                                                  I didn't find the solution that you think.........

                                                  please help me, i swear that i tried a lot of time.

                                                  if it is with variable, how can i send a variable from main.swf to index.swf????

                                                   

                                                  remember i am beginner and not a pro of actionscript...

                                                   

                                                  i will appreciate your help!!!

                                                   

                                                  kind regards,

                                                  MELAS076

                                                  • 22. Re: Problem to load XML
                                                    kglad Adobe Community Professional & MVP

                                                    i don't understand what problem you could have now because you now know the correct path.

                                                    • 23. Re: Problem to load XML
                                                      melas076 Level 1

                                                      which one is the correct path?

                                                      • 24. Re: Problem to load XML
                                                        melas076 Level 1

                                                        dear kglad,

                                                         

                                                        you wrote this:

                                                         

                                                        when you want the one in multihost, use

                                                         

                                                        var a:String="products/multihost";

                                                        xmlOb.load(a+"/datas.xml");

                                                         

                                                        and when you want the one in VOIP, use:

                                                         

                                                        var a:String="products/VOIP";

                                                        xmlOb.load(a+"/datas.xml");

                                                         

                                                         

                                                        I know that is correct but my problem index.swf is the same for all projects and when i click from main.swf the 2 products it gives me the product1 is "products/multihost".

                                                         

                                                        so from the main to index.swf, how can i give a command to have the path folder to read datas.xml in index.swf when 1 of products clicked?

                                                         

                                                         

                                                        regards,

                                                        MELAS076

                                                        • 25. Re: Problem to load XML
                                                          kglad Adobe Community Professional & MVP

                                                          use:

                                                           

                                                           

                                                          // in main swf's main timeline

                                                          var mainS:String="products/multihost";

                                                          xmlOb.load(mainS+"/datas.xml");

                                                           

                                                          var indexS:String="products/VOIP";

                                                           

                                                           

                                                          // in index swf

                                                          xmlOb.load(_root.indexS+"/datas.xml");