A Flash Developer Resource Site

Results 1 to 16 of 16

Thread: Slideshow skipping first image...

  1. #1
    Dumbass grBMXer's Avatar
    Join Date
    May 2002
    Location
    Grand Rapids, MI, USA
    Posts
    212

    Slideshow skipping first image...

    Hi,

    I have a slideshow that loads in an xml file and then loads in and out of the images specified within the file. It was working great and then I had noticed that it keeps skipping over the first image. When it loops back around it displays it but when you first go to the page that would have the slideshow on it, it skips the first image.

    To see what I mean please check out http://www.evanbartlett.com/gyslide/

    When it loads you'll notice how it goes blank for a few seconds before fading in with the image, which happens to be the second image and not the first. I'm not sure what it would be doing to cause this. Below is the actionscript for my flash file.

    PHP Code:
    // 1st frame AS
    // Disable slideshow movie scaling
    fscommand("allowscale""false");
    // Hide the captions box while images are loading
    this.caption._visible false;
    // Load and parse the slideshow variables
    xmlData = new XML();
    xmlData.ignoreWhite true;
    xmlData.onLoad parse_data;
    xmlData.load("photos.xml");
    // Function: parse_data
    // 
    // Parameters: success - bollean.
    // 
    // Description:
    // Checks to see if the XML data being loaded into the XML object had loaded
    // properly.  If it has, call parseXmlArray passing it the XML object.  Otherwise,
    // output an error.
    function parse_data(success) {
        if (
    success == true) {
            
    xmlData parseXmlToArray(xmlData.firstChild);
            
    // xml_data.text = "Parse was succsessful.  Use debug to view the xmlData variable.";
        
    }
        
    // else {
        // xml_data.text = "Error:\nThe XML document did not load properly.\n";
        // }
    }
    // Constructor:
    // multiNodeObject
    // 
    // Methods:
    // - length()
    // returns number of numbered items in the object.
    // Default Constructor
    function multiNodeObject() {
    }
    // Inherits properties from class object
    multiNodeObject.prototype = new Object();
    // Length method:
    // Caculates and returns the number of numbered items in the object
    multiNodeObject.prototype.length = function() {
        var 
    count 0;
        for (var 
    name in this) {
            var 
    addCount true;
            for (var 
    0i<name.lengthi++) {
                if (
    name.charCodeAt(i)<48 || name.charCodeAt(i)>57) {
                    
    addCount false;
                }
            }
            if (
    addCount) {
                
    count++;
            }
        }
        return 
    count;
    };
    // Register the Class multiNodeObject
    Object.registerClass("multiNodeObject"multiNodeObject);
    // Parameters: xm - a 'loaded' XML object.
    // 
    // Returns: temp_obj = an array ojbect
    // 
    // Description:
    // This function recursivly traverses through an XML object creates a series
    // of embedded arrays using nodeNames and nodeValues.  The result is an array
    // object of that XML data that can be accessed through dot indexing.
    function parseXmlToArray(xm) {
        
    // temporary object that will be returned
        
    var temp_obj = new Object();
        
    // Checks to see if the current xml object has any children.  If it doesn't,
        // There is not data here and the function will end.
        
    if (xm.hasChildNodes() && xm.childNodes.length>1) {
            
    temp_obj[xm.nodeName] = new multiNodeObject();
            for (var 
    0i<xm.childNodes.lengthi++) {
                
    temp_obj[xm.nodeName][i] = parseXmlToArray(xm.childNodes[i]);
            }
        } else if (
    xm.hasChildNodes() && xm.childNodes.length == 1) {
            if (
    xm.firstChild.nodeType == 1) {
                
    temp_obj[xm.nodeName] = parseXmlToArray(xm.firstChild);
            } else if (
    xm.firstChild.nodeType == 3) {
                var 
    temp2 = new Object();
                
    temp2["value"] = xm.firstChild.nodeValue;
                
    // Outputs the current nodes' attributs array to the xml_data textbox
                
    if (xm.attributes) {
                    for (var 
    name in xm.attributes) {
                        
    temp2[name] = xm.attributes[name];
                        
    // xml_data.text = xml_data.text + "-" + name + " : " + xm.attributes[name] + "\n";
                    
    }
                }
                
    temp_obj[xm.nodeName] = temp2;
            }
        }
        
    // Outputs the current nodes' attributs array to the xml_data textbox
        
    if (xm.attributes) {
            for (var 
    name in xm.attributes) {
                
    temp_obj[xm.nodeName][name] = xm.attributes[name];
                
    // xml_data.text = xml_data.text + "-" + name + " : " + xm.attributes[name] + "\n";
            
    }
        }
        return 
    temp_obj;
    }

    // 3rd frame AS
    // Check to see if the XML data has been parsed.  If it has, store
    // the parsed XML variables into the flash application.  Otherwise,
    // loop back to wait.
    if (xmlData.loaded == false) {
        
    gotoAndPlay(_currentframe-1);
    } else {
        
    // The folder that the images are stored in
        
    this.image_folder xmlData.slideshow[0].settings[0].image_folder.value;
        
    // The number of images the slideshow will play
        
    this.numImages xmlData.slideshow[1].images.length();
        
    // Number of seconds each images will be shown for
        
    this.time Number(xmlData.slideshow[0].settings[1].time.value);
        
    // Number of seconds each images takes to fade in a out
        
    this.fade Number(xmlData.slideshow[0].settings[2].fade.value);
        
    // Whether the cycle of images should repeat or not
        
    this.repeat true;
        
    // Whether the captions box should be shown
        
    this.captions xmlData.slideshow[0].settings[4].captions.value;
        
    // Width of the slideshow movie
        
    this.movie_width 280;
        
    // Heighth of the slideshow movie
        
    this.movie_height 212;
        
    // Hide the dropzone movie where the images will be loaded to
        
    this.image_dropzone._visible false;
        
    // Set the first image to be played
        
    this.currentImage 1;
        
    // Set the last image that was played
        
    this.oldImage 0;
        
    // Set whether the image has been shown or not
        
    this.imageShown 0;
        
    // Number of frames that makes up a second
        
    this.second 31;
        
    // Starting value for the counter
        
    this.counter 0;
    }

    // 4th frame AS
    // Load all the images from the XML data 

    for(var i=1i<=numImagesi++){
        
    this.image_dropzone.duplicateMovieClip("image_dropzone" ii);
        
    this["image_dropzone" i].loadMovie(this.image_folder xmlData.slideshow[1].images[i-1].image[0].file.value);
    }

    // 5th frame AS
    // Loop through all the images that have been loaded into the
    // slideshow
    for (var 1i<=numImagesi++) {
        
    // Check to see if see if 'i' matches the current image to be shown
        
    if (== this.currentImage) {
            
    // Check to see if the image to be shown is loaded or not
            
    if (this["image_dropzone"+this.currentImage].getBytesLoaded()>=this["image_dropzone"+this.currentImage].getBytesTotal()) {
                
    // Check to see if the image has been shown yet
                
    if (this.imageShown == && this.currentImage != this.oldImage) {
                    
    // Show the image and prep it for fading
                    
    this["image_dropzone"+this.currentImage]._visible true;
                    
    this["image_dropzone"+this.currentImage]._alpha 0;
                    
    this.imageShown 1;
                    
    this.loader._visible false;
                    
    // If the image has already been shown and preped
                
    } else {
                    
    // Check to see if the images needs to be faded in
                    
    if (this.currentImage != this.oldImage && this.fade>0) {
                        
    // Fade in the image
                        
    this["image_dropzone"+this.currentImage]._alpha 100*(this.counter/(this.fade*this.second));
                        
    this.loader._visible false;
                        
    // If the image does not need to be faded in
                    
    } else {
                        
    // Show the image
                        
    this["image_dropzone"+this.currentImage]._alpha 100;
                        
    this.loader._visible false;
                    }
                    
    // Move the image to the middle of the slideshow screen
                    
    this["image_dropzone"+this.currentImage]._x = (this.movie_width-this["image_dropzone"+this.currentImage]._width)/2;
                    
    this["image_dropzone"+this.currentImage]._y = (this.movie_height-this["image_dropzone"+this.currentImage]._height)/2;
                    
    // Check to see if captions should be shown
                    
    if (this.captions == true || this.captions == "true") {
                        
    // Make the captions box visible and load the caption text for the current image
                        
    this.caption._visible true;
                        
    this.caption.tb_caption.text xmlData.slideshow[1].images[i-1].image[1].caption.value;
                        
    // If captions should not be shown
                    
    } else {
                        
    // Hide the captions box
                        
    _root.caption._visible false;
                    }
                    
    // Swap depths of images so everything is layered in the correct order
                    
    this.photo_frame.swapDepths(numImages+3);
                    
    this.caption.swapDepths(numImages+2);
                }
                
    // If the current image has not been fully loaded, hide it
            
    } else {
                
    this["image_dropzone"+i]._visible false;
                
    this.loader._visible true;
            }
            
    // Check to see if 'i' is the old image
        
    } else if (== this.oldImage && this.fade>0) {
            
    // Fade the old image out
            
    this["image_dropzone"+this.oldImage]._alpha 100-(100*(this.counter/(this.fade*this.second)));
            
    // If 'i' is not the current image or the old image, hide image 'i'
        
    } else {
            
    this["image_dropzone"+i]._visible false;
        }
    }
    // Increment the counter
    this.counter++;
    // Check to see if the counter has exceeded the fade and time to show the image
    if (this.counter>((this.time+this.fade)*this.second)) {
        
    // Reset the counter
        
    this.counter 0;
        
    // Set the current image as the old image
        
    this.oldImage this.currentImage;
        
    // Increment the current image
        
    this.currentImage++;
        
    // Check to see if the current image exceeds the number of images in the slideshow
        
    if (this.currentImage>numImages) {
            
    // Check to see if the slideshow should be repeated
            
    if (this.repeat == true) {
                
    // Set the current image back to the beginning
                
    this.currentImage 1;
                
    // If the slideshow is not to be repeated, hold on the last image
            
    } else {
                
    this.currentImage this.numImages;
            }
        }
        
    // Set the current image as not shown
        
    this.imageShown 0;
    }

    //6th frame AS
    // Loop back to and play
    gotoAndPlay(_currentframe 1); 
    Any help would be much appreciated. Thanks in advance!

    Evan
    Last edited by tupps; 11-16-2005 at 06:56 PM. Reason: Put code in PHP blocks so it doesn't cause sideways scrolling
    [+] Website. http://www.evanbartlett.com/
    [+] Email. evan@evanbartlett.com
    [+] AIM. emDUB123456789
    [+] Yahoo! evanem1

  2. #2
    Senior Member tupps's Avatar
    Join Date
    Jan 2001
    Location
    Melbourne
    Posts
    2,035
    I am not sure if this is the issue, but an easier way that looping on Frame3 to see if the data is loaded is to put a stop statement after the xml.load, and then put a gotoAndPlay(3) in the parse_data function. Try that as you might be picking up the data between the XML being loaded and your parsing routines running. Put a trace statement in the parser and the code on frame 3 to see if this is happening.

    Thanks

    Luke
    Flash-XML FAQ
    http://www.tupps.com/flash/faq/

  3. #3
    Dumbass grBMXer's Avatar
    Join Date
    May 2002
    Location
    Grand Rapids, MI, USA
    Posts
    212
    hey thanks a lot for your response. i guess i'm kind of lost on the trace idea you have, can you possibly show me a little example if that isn't took much to ask?
    [+] Website. http://www.evanbartlett.com/
    [+] Email. evan@evanbartlett.com
    [+] AIM. emDUB123456789
    [+] Yahoo! evanem1

  4. #4
    Dumbass grBMXer's Avatar
    Join Date
    May 2002
    Location
    Grand Rapids, MI, USA
    Posts
    212
    yeah i didn't know what you meant by the trace idea but i did try the stop(); and then the gotoandplay in the parse_data. still doing the same thing. got any other ideas why it's doing this?
    [+] Website. http://www.evanbartlett.com/
    [+] Email. evan@evanbartlett.com
    [+] AIM. emDUB123456789
    [+] Yahoo! evanem1

  5. #5
    Senior Member tupps's Avatar
    Join Date
    Jan 2001
    Location
    Melbourne
    Posts
    2,035
    It is hard to work out where the problem is without having your application to debug. Have a look at the actionscript dictionary about the trace statement which allows you to see what your variables are doing, or read up on debugging a flash movie.

    Either way you will be able to get an insight into what your code is doing.

    Thanks

    Luke
    Flash-XML FAQ
    http://www.tupps.com/flash/faq/

  6. #6
    Dumbass grBMXer's Avatar
    Join Date
    May 2002
    Location
    Grand Rapids, MI, USA
    Posts
    212
    alright, thanks. i'll take a look. i did notice however. the first time you go to the slideshow is the only time it skips the first image. once it loops through it starts showing it and if you were to come back to the slideshow later on it shows it right away also. but as soon as you delete all your files from the net it doesn't show it again.

    it's definetly starting to play before everything is loaded it seems.
    [+] Website. http://www.evanbartlett.com/
    [+] Email. evan@evanbartlett.com
    [+] AIM. emDUB123456789
    [+] Yahoo! evanem1

  7. #7
    Dumbass grBMXer's Avatar
    Join Date
    May 2002
    Location
    Grand Rapids, MI, USA
    Posts
    212
    I've tried a million things and still no answer. Now I've attached the .fla so if anyone could please take a look at it I would greatly appreciate it.

    The xml file that it pulls from looks like this.

    HTML Code:
    <?xml version="1.0" ?>
    <slideshow>
    <settings>
    <image_folder>home/</image_folder>
    <time>3</time>
    <fade>2</fade>
    <repeat>true</repeat>
    <captions>false</captions>
    </settings>
    <images>
    <image><file>01.jpg</file><caption><![CDATA[NO COMMENT...]]></caption></image>
    <image><file>02.jpg</file><caption><![CDATA[NO COMMENT...]]></caption></image>
    <image><file>03.jpg</file><caption><![CDATA[NO COMMENT...]]></caption></image>
    <image><file>04.jpg</file><caption><![CDATA[NO COMMENT...]]></caption></image>
    <image><file>05.jpg</file><caption><![CDATA[NO COMMENT...]]></caption></image>
    <image><file>06.jpg</file><caption><![CDATA[NO COMMENT...]]></caption></image>
    </images>
    </slideshow>
    Thanks a lot!
    Attached Files Attached Files
    [+] Website. http://www.evanbartlett.com/
    [+] Email. evan@evanbartlett.com
    [+] AIM. emDUB123456789
    [+] Yahoo! evanem1

  8. #8
    Dumbass grBMXer's Avatar
    Join Date
    May 2002
    Location
    Grand Rapids, MI, USA
    Posts
    212
    *bump, anyone? think this post would do better in a different area of the forum?
    [+] Website. http://www.evanbartlett.com/
    [+] Email. evan@evanbartlett.com
    [+] AIM. emDUB123456789
    [+] Yahoo! evanem1

  9. #9
    Dumbass grBMXer's Avatar
    Join Date
    May 2002
    Location
    Grand Rapids, MI, USA
    Posts
    212
    *bump
    [+] Website. http://www.evanbartlett.com/
    [+] Email. evan@evanbartlett.com
    [+] AIM. emDUB123456789
    [+] Yahoo! evanem1

  10. #10
    Senior Member tupps's Avatar
    Join Date
    Jan 2001
    Location
    Melbourne
    Posts
    2,035
    I downloaded your file, but you haven't provided the images etc and it causes flash to lock up. If you want someone to look at it I suggest you provide a zip file with everything in it that is needed to run the flash application.
    Flash-XML FAQ
    http://www.tupps.com/flash/faq/

  11. #11
    :
    Join Date
    Dec 2002
    Posts
    3,518
    It works locally, so it appears that the first picture hasn't had time to fully load before it reaches this
    Code:
    	// Check to see if the image to be shown is loaded or not
    	if (this["image_dropzone"+this.currentImage].getBytesLoaded()>=this["image_dropzone"+this.currentImage].getBytesTotal()) {
    and the else statement says make it invisible and continue on to the next picture.

    To verify this, you can try adding a few more frames between the load and display frames, which will give the first picture time to finish loading.

    Hope this helps.

  12. #12
    Dumbass grBMXer's Avatar
    Join Date
    May 2002
    Location
    Grand Rapids, MI, USA
    Posts
    212
    Cool well I tried it and didn't have any luck. But I was wondering. Is there a way I could add a frame or 2 between the load and display frames where it would check and make sure all the images are completely loaded before moving to the display? Wouldn't take to much to accomplish this would it?
    [+] Website. http://www.evanbartlett.com/
    [+] Email. evan@evanbartlett.com
    [+] AIM. emDUB123456789
    [+] Yahoo! evanem1

  13. #13
    Dumbass grBMXer's Avatar
    Join Date
    May 2002
    Location
    Grand Rapids, MI, USA
    Posts
    212
    *bump

    is there anyway i could add a couple frames to check if the images loaded from the xml are completely loaded before moving to the display area?
    [+] Website. http://www.evanbartlett.com/
    [+] Email. evan@evanbartlett.com
    [+] AIM. emDUB123456789
    [+] Yahoo! evanem1

  14. #14
    Dumbass grBMXer's Avatar
    Join Date
    May 2002
    Location
    Grand Rapids, MI, USA
    Posts
    212
    ok so i tried to add 2 frames between the display and load images frames and place this code in the second frame i added.

    Code:
    for(var i=1; i<=numImages; i++){
    	if (_root["image_dropzone"+ i].getBytesLoaded()>=_root["image_dropzone"+ i].getBytesTotal()) {
    	// if image is loaded keep playing
    	}else{
    	// if image is not loaded go back
    	gotoAndPlay(_currentframe - 1);
    	}
    }
    didn't seem to help my problem. got any ideas on what i could do?
    [+] Website. http://www.evanbartlett.com/
    [+] Email. evan@evanbartlett.com
    [+] AIM. emDUB123456789
    [+] Yahoo! evanem1

  15. #15
    :
    Join Date
    Dec 2002
    Posts
    3,518
    This one has a preloader for all the images, see if it solves your problem.
    See attached file.
    Last edited by dawsonk; 08-22-2007 at 10:52 AM.

  16. #16
    Dumbass grBMXer's Avatar
    Join Date
    May 2002
    Location
    Grand Rapids, MI, USA
    Posts
    212
    sorry for the slow response. it worked great. thank you very much for your help!
    [+] Website. http://www.evanbartlett.com/
    [+] Email. evan@evanbartlett.com
    [+] AIM. emDUB123456789
    [+] Yahoo! evanem1

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center