6 Replies Latest reply on May 6, 2010 4:08 AM by DigiFront

    Loading random images with text info into MC with xml

    DigiFront

      Hi there!

       

      How would one load 3 random images with text and a url link using xml?

       

      See attached idea jpg

       

      idea.jpg

        • 1. Re: Loading random images with text info into MC with xml
          kglad Adobe Community Professional & MVP

          xml is used to store data.  flash can load and utilize that data.  sometimes it makes sense for flash to use xml to present data to users.

           

          whether it makes sense for you or not, depends on your project needs.  knowing you want to display images,  descriptions and urls isn't enough to determine whether you should use xml to store your image, description, url data.

          1 person found this helpful
          • 2. Re: Loading random images with text info into MC with xml
            DigiFront Level 1

            Thanks Kglad...

             

            I was wondering as there would be 3 folders with various images that would change on an irregular basis and the info that goes with it. On visiting the site the files would randomly select from the folders for information, the corresponding image and a link to page relevant to the image... I was thinking 3 xml lists that could be updated as the files been added or removed might have been a solution?...

             

            If you have any suggestions or so it would be highly valued.

            • 3. Re: Loading random images with text info into MC with xml
              kglad Adobe Community Professional & MVP

              you should avoid using multiple xml files unless there's a reason.  one good reason to use different xml files would be because each file stores data completely unrelated to the data in the other files.  and another reason might be that one xml file would be so large it would be unwieldy and difficult to use if all the data were in that one.

               

              my impression is that you should use one xml file for your project.

               

              you might use something like:

               

              <data>

              <image src="folder1/image1.jpg" description="xxx" url="www.adobe.com"/>

              <image src="folder2/image1.jpg" description="yyy"  url="www.kglad.com"/>

              <image src="folder2/image2.jpg" description="zzz"  url="www.flash.com"/>

              .

              .

              .

              </data>

              1 person found this helpful
              • 4. Re: Loading random images with text info into MC with xml
                DigiFront Level 1

                I guess that it would be layout out in that manner... Thanks for that, the catch would be to have 3 coloumns that would randomly select from that xml and check each other to not have the same info?...

                • 5. Re: Loading random images with text info into MC with xml
                  kglad Adobe Community Professional & MVP

                  you could use:

                   

                  var xml:XML=new XML();

                  xml.ignoreWhite=true;

                  xml.onLoad=parseXML;

                  xml.load("yourxml.xml");

                   

                  function parseXML(){

                  var a:Array=[];

                  for(var i:Number=0;i<this.firstChild.childNodes.length;i++){

                  a.push(this.firstChild.childNodes[i]);

                  }

                  shuffle(a);

                  displayF(a);

                  }

                   

                  function displayF(a:Array){

                  // display the contents of a[0],a[1],a[2]

                  }

                   

                  function shuffle(a:Array):Array {
                      var len:Number = a.length-1;
                      for (var ivar:Number = len; ivar>=0; ivar--) {
                          var p:Number = Math.floor(Math.random()*(ivar+1));
                          var t = a[ivar];
                          a[ivar] = a[p];
                          a[p] = t;
                      }
                      return a;
                  }

                  • 6. Re: Loading random images with text info into MC with xml
                    DigiFront Level 1

                    Thanks Kglad,

                     

                    Will play around with it much appreciated!!