5 Replies Latest reply on Nov 1, 2011 5:20 AM by Ned Murphy

    Help with AS2 - photo gallery

    DK1120 Level 1

      Hi All

       

      would someone beable to help me with some code, I downloaded a photo gallery example, at the moment the movie plays the photos when you click a button(timer)

       

      What I'm trying to do is to get the movie to auto play the photos on load rather than having to click the button. I have been lookin in the scrip, I think its something to do with

       

      // initialize values

        currentIndex = 0;

       

      but when I change this value to 1, not much happens, would some be able to have a look within the code and see where I can change it so that the movie runs the images automatcally on load.

      I have pasted the code below, hope this is ok?

       

      many thanks for anyones help!

       

       

       

      CODE:

       

      // (c) Copyright by Andrew DiFiore. All rights reserved. DO NOT REMOVE.
      fscommand("allowscale", "false");
      Stage.scaleMode = "noScale";

      targetPhoto._visible = false;

      slides_xml = new XML();
      slides_xml.onLoad = loadSlideShow;
      slides_xml.load("album.xml");
      slides_xml.ignoreWhite = true;

      function loadSlideShow(success) {
      if (success == true) {
        rootNode = slides_xml.firstChild;
        totalSlides = rootNode.childNodes.length;
        currentSlideNode = rootNode.firstChild;                            
        photos = new Array(totalSlides);
        thumbs = new Array(totalSlides);
        captions = new Array(totalSlides);  
        tx = 0;
        for (i=0; i < totalSlides; i++) { // populate arrays and create thumbnails dynamically
         photos[i] = currentSlideNode.attributes.jpegURL;
         thumbs[i] = [currentSlideNode.attributes.jpegWidth,currentSlideNode.attributes.jpegHeight];
         captions[i] = currentSlideNode.firstChild.nodeValue;
         _root.attachMovie("thumb","thumb"+i,i);
         _root["thumb"+i]._x = tx;
         _root["thumb"+i]._y = 595; // using fixed Y coord
         _root["thumb"+i].tindex = i;
         tx += 22;  
         currentSlideNode = currentSlideNode.nextSibling;
        }
        // initialize values                      <<<<<<<<<<<<<<<<<<<<<<<IS IT HERE?????
        currentIndex = 0;
        targetWidth=thumbs[currentIndex][0]; // get width
        targetHeight=thumbs[currentIndex][1]; // get height;
        updateSlide();
      }
      }

      function updateSlide() { // load photo, update caption and status fields
      targetPhoto.loadPhoto(photos[currentIndex]);
      caption = captions[currentIndex];
      statusField = (currentIndex+1) + "/" + totalSlides;
      }

      function slideShow() {
      if (currentIndex == totalSlides-1) { currentIndex = 0; } else { currentIndex++; }
      targetPhoto._visible = false;
      targetWidth=thumbs[currentIndex][0]; // get width
      targetHeight=thumbs[currentIndex][1]; // get height;
      updateSlide();
      }

      MovieClip.prototype.loadPhoto = function(fn) { // load external jpeg method + preloader
      this.createEmptyMovieClip("holder", 1);
      this.holder.loadMovie(fn);
      this.onEnterFrame = function() { // NOTE: could use this to display percentage to user
        if (Math.floor((this.holder.getBytesLoaded()/this.holder.getBytesTotal())*100) >= 100) {
         delete this.onEnterFrame;
          }
      }
      }