17 Replies Latest reply on Oct 11, 2010 6:19 PM by kglad

    Loop images

    Ron Colmen Level 2

      I want my XML driven pic gallery to showup each of my 15 images one after the other. But There's something wrong in my code. I'm getting 'undefined' at the start.

       

      _root.myImages = myGalleryXML.firstChild.childNodes;

      _root.myImagesTotal = myImages.length;

       

      function myShow() {

      myURLA = myImages[myNumber].attributes.full_url;

      myTitleA = myImages[myNumber].attributes.heading;

      myCaptionA = myImages[myNumber].attributes.title;

       

           if(myNumber < myImages-1) {

                myNumber++;

           } else {

                myNumber = 0;

           }

      _root.holder.loadMovie("http://www.abc/photos/"+myURLA+");

      _root.caption.text = myCaptionA;

      _root.heading.text = myTitleA;

      }

      var IntervalID = setInterval(myShow, 6000);

       

      function callFullImage(myNumber) {  //calls on press of a button

      myURL = myImages[myNumber].attributes.full_url;

       

      var fullClipLoader = new MovieClipLoader();

      var fullPreloader = new Object();

      fullClipLoader.addListener(fullPreloader);

       

      fullClipLoader.loadClip("http://www.abc.com/photos/"+myURL,fullImg_mc);

      }

        • 1. Re: Loop images
          kglad Adobe Community Professional & MVP

          if myURLA is correct, fix:

           

          _root.holder.loadMovie("http://www.abc/photos/"+myURLA+");

           

          to

           

          _root.holder.loadMovie("http://www.abc/photos/"+myURLA");

           


          _root.myImages = myGalleryXML.firstChild.childNodes;

          _root.myImagesTotal = myImages.length;

           

          function myShow() {

          myURLA = myImages[myNumber].attributes.full_url;

          myTitleA = myImages[myNumber].attributes.heading;

          myCaptionA = myImages[myNumber].attributes.title;

           

               if(myNumber < myImages-1) {

                    myNumber++;

               } else {

                    myNumber = 0;

               }

          _root.holder.loadMovie("http://www.abc/photos/"+myURLA");

          _root.caption.text = myCaptionA;

          _root.heading.text = myTitleA;

          }

          var IntervalID = setInterval(myShow, 6000);

           

           

          function callFullImage(myNumber) {  //calls on press of a button

          myURL = myImages[myNumber].attributes.full_url;

           

          var fullClipLoader = new MovieClipLoader();

          var fullPreloader = new Object();

          fullClipLoader.addListener(fullPreloader);

           

          fullClipLoader.loadClip("http://www.abc.com/photos/"+myURL,fullImg_mc);

          }

          • 2. Re: Loop images
            Ron Colmen Level 2

            that didn't work!

             

            myURLA is correct.

             

            I have my doubts with the myNumber. Is there any other way to get this working?

            • 3. Re: Loop images
              kglad Adobe Community Professional & MVP

              you should see a lot of compiler errors with that code.  so, something doesn't make sense.

               

              copy and paste the code you tried that didn't work.

              • 4. Re: Loop images
                Ron Colmen Level 2

                XML

                <image thumb_url="thumb1.jpg" full_url="photo1.jpg" title="text A" heading="text B" />

                 

                AS

                myGalleryXML.onLoad = function() {

                _root.myImages = myGalleryXML.firstChild.childNodes;

                _root.myImagesTotal = myImages.length;

                 

                myShow();

                };

                 

                function myShow() {

                myURLA = myImages[myNumber].attributes.full_url;

                myTitleA = myImages[myNumber].attributes.heading;

                myCaptionA = myImages[myNumber].attributes.title;

                 

                     if(myNumber < myImages-1) {

                          myNumber++;

                     } else {

                          myNumber = 0;

                     }

                _root.holder.loadMovie("http://www.abc.com/photos/"+myURLA);

                _root.caption.text = myCaptionA;

                _root.heading.text = myTitleA;

                }

                var IntervalID = setInterval(myShow, 6000);

                 

                function callFullImage(myNumber) {

                myURL = myImages[myNumber].attributes.full_url;

                myTitle = myImages[myNumber].attributes.heading;

                myCaption = myImages[myNumber].attributes.title;

                "my_mc"

                 

                var fullClipLoader = new MovieClipLoader();

                var fullPreloader = new Object();

                fullClipLoader.addListener(fullPreloader);

                 

                fullPreloader.onLoadStart = function(target) {

                "heading"

                heading.selectable = false;

                };

                 

                fullPreloader.onLoadProgress = function(target, loadedBytes, totalBytes) {

                count.text = Math.floor((loadedBytes/totalBytes)*100);

                };

                 

                fullPreloader.onLoadComplete = function(target) {

                new Tween(target, "_alpha", Strong.easeOut, 0, 100, .5, true);

                heading.text = myTitle;

                caption.text = myCaption;

                };

                fullClipLoader.loadClip("http://www.abc.com/photos/"+myURL,my_mc);

                }

                • 5. Re: Loop images
                  kglad Adobe Community Professional & MVP

                  your if-statement isn't correct.  fix that next and make sure myNumber is initialized:

                   

                    if(myNumber < _root.myImagesTotal-1) {

                  • 6. Re: Loop images
                    Ron Colmen Level 2

                    Replacing if(myNumber < _root.myImagesTotal-1) { did not work.

                     

                    With the current code (before adding if(myNumber < _root.myImagesTotal-1) {).

                    1. Starts with no image | title: 'undefined' | caption: 'undefined'

                    //after the setInterval

                    2. Shows the first image, first heading and the first caption.

                    //after the setInterval

                    3. keeps on repeating the first image, first heading and first caption.

                    • 7. Re: Loop images
                      kglad Adobe Community Professional & MVP

                      if your xml parsing is incorrect, you need to correct that.  those errors need to be fixed first.

                       

                      you should be showing your xml handling code and structure of your xml file.

                      • 8. Re: Loop images
                        Ron Colmen Level 2

                        This is my XML and AS.

                         

                        XML

                        <image thumb_url="thumb1.jpg" full_url="photo1.jpg" title="text A" heading="text B" />

                         

                        AS

                        myGalleryXML.onLoad = function() {

                        _root.myImages = myGalleryXML.firstChild.childNodes;

                        _root.myImagesTotal = myImages.length;

                        myShow();

                        };

                         

                         

                        I'm not seen why isn't my code working. Could you show me how to make my 15 images show one after the other every 10seconds and loop.

                        • 9. Re: Loop images
                          kglad Adobe Community Professional & MVP

                          that xml isn't going to work.  you must have a root node.  show it.

                          • 10. Re: Loop images
                            Ron Colmen Level 2

                            <pics thumb_width="10" thumb_height="60" gallery_width="10" gallery_height="40" gallery_x="5" gallery_y="5" full_x="20" full_y="5">

                            <image thumb_url="thumb1.jpg" full_url="photo1.jpg" title="Text A1" heading="Text B1" />

                            <image thumb_url="thumb1.jpg" full_url="photo1.jpg" title="Text A2" heading="Text B2" />

                            //so on

                            </pics>

                            • 11. Re: Loop images
                              kglad Adobe Community Professional & MVP

                              where's your loading code etc?


                              • 12. Re: Loop images
                                Ron Colmen Level 2

                                myGalleryXML.onLoad = function() {

                                _root.gallery_x = myGalleryXML.firstChild.attributes.gallery_x;

                                _root.gallery_y = myGalleryXML.firstChild.attributes.gallery_y;

                                _root.gallery_width = myGalleryXML.firstChild.attributes.gallery_width;

                                _root.gallery_height = myGalleryXML.firstChild.attributes.gallery_height;

                                 

                                _root.myImages = myGalleryXML.firstChild.childNodes;

                                _root.myImagesTotal = myImages.length;

                                 

                                _root.thumb_height = myGalleryXML.firstChild.attributes.thumb_height;

                                _root.thumb_width = myGalleryXML.firstChild.attributes.thumb_width;

                                 

                                _root.full_x = myGalleryXML.firstChild.attributes.full_x;

                                _root.full_y = myGalleryXML.firstChild.attributes.full_y;

                                 

                                myShow();

                                };

                                 

                                 

                                 

                                function myShow() {

                                myURLA = myImages[myNumber].attributes.full_url;

                                myTitleA = myImages[myNumber].attributes.heading;

                                myCaptionA = myImages[myNumber].attributes.title;

                                 

                                     if(myNumber < myImages-1) {

                                          myNumber++;

                                     } else {

                                          myNumber = 0;

                                     }

                                _root.holder.loadMovie("http://www.abc.com/photos/"+myURLA);

                                _root.caption.text = myCaptionA;

                                _root.heading.text = myTitleA;

                                }

                                var IntervalID = setInterval(myShow, 6000);

                                 

                                 

                                 

                                function callFullImage(myNumber) {

                                 

                                myURL = myImages[myNumber].attributes.full_url;

                                myTitle = myImages[myNumber].attributes.heading;

                                myCaption = myImages[myNumber].attributes.title;

                                "my_mc"

                                 

                                var fullClipLoader = new MovieClipLoader();

                                var fullPreloader = new Object();

                                fullClipLoader.addListener(fullPreloader);

                                 

                                fullPreloader.onLoadStart = function(target) {

                                "heading"

                                heading.selectable = false;

                                };

                                 

                                fullPreloader.onLoadProgress = function(target, loadedBytes, totalBytes) {

                                count.text = Math.floor((loadedBytes/totalBytes)*100);

                                };

                                 

                                fullPreloader.onLoadComplete = function(target) {

                                new Tween(target, "_alpha", Strong.easeOut, 0, 100, .5, true);

                                heading.text = myTitle;

                                caption.text = myCaption;

                                };

                                fullClipLoader.loadClip("http://www.abc.com/photos/"+myURL,my_mc);

                                }

                                • 13. Re: Loop images
                                  kglad Adobe Community Professional & MVP

                                  jeez, are you loading your xml?


                                  • 14. Re: Loop images
                                    Ron Colmen Level 2

                                    Oops! sorry. Here goes the full code.

                                     

                                     

                                    import mx.transitions.Tween;

                                    import mx.transitions.easing.*;

                                    var myGalleryXML = new XML();

                                    myGalleryXML.ignoreWhite = true;

                                    myGalleryXML.load("http://www.abc.com/mygallery.xml");

                                     

                                    myGalleryXML.onLoad = function() {

                                    _root.gallery_x = myGalleryXML.firstChild.attributes.gallery_x;

                                     

                                    _root.gallery_y = myGalleryXML.firstChild.attributes.gallery_y;

                                    _root.gallery_width = myGalleryXML.firstChild.attributes.gallery_width;

                                    _root.gallery_height = myGalleryXML.firstChild.attributes.gallery_height;

                                     

                                    _root.myImages = myGalleryXML.firstChild.childNodes;

                                    _root.myImagesTotal = myImages.length;

                                     

                                    _root.thumb_height = myGalleryXML.firstChild.attributes.thumb_height;

                                    _root.thumb_width = myGalleryXML.firstChild.attributes.thumb_width;

                                     

                                    _root.full_x = myGalleryXML.firstChild.attributes.full_x;

                                    _root.full_y = myGalleryXML.firstChild.attributes.full_y;

                                     

                                    myShow();

                                    };

                                     

                                    function myShow() {

                                    myURLA = myImages[myNumber].attributes.full_url;

                                    myTitleA = myImages[myNumber].attributes.heading;

                                    myCaptionA = myImages[myNumber].attributes.title;

                                     

                                         if(myNumber < myImages-1) {

                                              myNumber++;

                                         } else {

                                              myNumber = 0;

                                         }

                                    _root.holder.loadMovie("http://www.abc.com/photos/"+myURLA);

                                    _root.caption.text = myCaptionA;

                                    _root.heading.text = myTitleA;

                                    }

                                    var IntervalID = setInterval(myShow, 6000);

                                     

                                    function callFullImage(myNumber) {

                                     

                                    myURL = myImages[myNumber].attributes.full_url;

                                    myTitle = myImages[myNumber].attributes.heading;

                                    myCaption = myImages[myNumber].attributes.title;

                                    "my_mc"

                                     

                                    var fullClipLoader = new MovieClipLoader();

                                    var fullPreloader = new Object();

                                    fullClipLoader.addListener(fullPreloader);

                                     

                                    fullPreloader.onLoadStart = function(target) {

                                    "heading"

                                    heading.selectable = false;

                                    };

                                     

                                    fullPreloader.onLoadProgress = function(target, loadedBytes, totalBytes) {

                                    count.text = Math.floor((loadedBytes/totalBytes)*100);

                                    };

                                     

                                    fullPreloader.onLoadComplete = function(target) {

                                    new Tween(target, "_alpha", Strong.easeOut, 0, 100, .5, true);

                                    heading.text = myTitle;

                                    caption.text = myCaption;

                                    };

                                    fullClipLoader.loadClip("http://www.abc.com/photos/"+myURL,my_mc);

                                    }

                                    • 15. Re: Loop images
                                      kglad Adobe Community Professional & MVP

                                      i don't see myNumber initialized.  use


                                       

                                       

                                      import mx.transitions.Tween;

                                      import mx.transitions.easing.*;

                                      var myGalleryXML = new XML();

                                      myGalleryXML.ignoreWhite = true;

                                      myGalleryXML.load("http://www.abc.com/mygallery.xml");

                                       

                                      myGalleryXML.onLoad = function() {

                                      _root.gallery_x = myGalleryXML.firstChild.attributes.gallery_x;

                                       

                                      _root.gallery_y = myGalleryXML.firstChild.attributes.gallery_y;

                                      _root.gallery_width = myGalleryXML.firstChild.attributes.gallery_width;

                                      _root.gallery_height = myGalleryXML.firstChild.attributes.gallery_height;

                                       

                                      _root.myImages = myGalleryXML.firstChild.childNodes;

                                      _root.myImagesTotal = myImages.length;

                                       

                                      _root.thumb_height = myGalleryXML.firstChild.attributes.thumb_height;

                                      _root.thumb_width = myGalleryXML.firstChild.attributes.thumb_width;

                                       

                                      _root.full_x = myGalleryXML.firstChild.attributes.full_x;

                                      _root.full_y = myGalleryXML.firstChild.attributes.full_y;

                                      myNumber=0;

                                      myShow();

                                      };

                                       

                                      function myShow() {

                                      myURLA = myImages[myNumber].attributes.full_url;

                                      myTitleA = myImages[myNumber].attributes.heading;

                                      myCaptionA = myImages[myNumber].attributes.title;

                                       

                                           if(myNumber < myImages-1) {

                                                myNumber++;

                                           } else {

                                                myNumber = 0;

                                           }

                                      _root.holder.loadMovie("http://www.abc.com/photos/"+myURLA);

                                      _root.caption.text = myCaptionA;

                                      _root.heading.text = myTitleA;

                                      }

                                      var IntervalID = setInterval(myShow, 6000);

                                       

                                      function callFullImage(myNumber) {

                                       

                                      myURL = myImages[myNumber].attributes.full_url;

                                      myTitle = myImages[myNumber].attributes.heading;

                                      myCaption = myImages[myNumber].attributes.title;

                                      "my_mc"

                                       

                                      var fullClipLoader = new MovieClipLoader();

                                      var fullPreloader = new Object();

                                      fullClipLoader.addListener(fullPreloader);

                                       

                                      fullPreloader.onLoadStart = function(target) {

                                      "heading"

                                      heading.selectable = false;

                                      };

                                       

                                      fullPreloader.onLoadProgress = function(target, loadedBytes, totalBytes) {

                                      count.text = Math.floor((loadedBytes/totalBytes)*100);

                                      };

                                       

                                      fullPreloader.onLoadComplete = function(target) {

                                      new Tween(target, "_alpha", Strong.easeOut, 0, 100, .5, true);

                                      heading.text = myTitle;

                                      caption.text = myCaption;

                                      };

                                      fullClipLoader.loadClip("http://www.abc.com/photos/"+myURL,my_mc);

                                      }

                                      • 16. Re: Loop images
                                        Ron Colmen Level 2

                                        Thanks Kglad.

                                        • 17. Re: Loop images
                                          kglad Adobe Community Professional & MVP

                                          you're welcome.