Xml slideshow lost its file paths while being repeatedly load/unload several times!

Kirupa’s xml-flash slideshow works fine when it is being implemented on its own timeline.

I made a sample project and externally loaded this slideshow by calling it thru loadMovie(). In the file that I’ve provided, you will see that once you’ve clicked the loadMovie button the slideshow is being loaded on the left side of the stage with no error.

The problems arises when you unloads and loads the movie repeatedly. The slideshow’s transition effects jumps too fast from one image to another, as if the image sequencing is gone. And if you test and try to click the buttons for more load and unload operations you will end up seeing the [COLOR=Red]“Error opening url - file://undefined”[/COLOR] - as if the movie cannot keep up with the phasing of button’s events!:sen:

**[COLOR=Blue]Here’s the codes:

In XML:

[/COLOR]**

<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<images>
    <pic>
        <image>pic1.jpg</image>
        <caption>Picture 1</caption>
    </pic>
    <pic>
        <image>pic2.jpg</image>
        <caption>Picture 2</caption>
    </pic>
    <pic>
        <image>pic3.jpg</image>
        <caption>Picture 3</caption>
    </pic>
    <pic>
        <image>pic4.jpg</image>
        <caption>Picture 4</caption>
    </pic>
</images>

**[COLOR=Blue]

Inside .FLA:

Main Movie:

[/COLOR]**

bigRed_btn._visible = false;
txtMovieNotLoaded._visible = false;

//Load Movie
bigBlue_btn.onRelease = function  () {
    loadMovie("slideshow.swf", slideshowHolder_mc);
    bigBlue_btn._visible = false;
    bigRed_btn._visible = true;
    txtMovieNotLoaded._visible = false;
    
}


//Unload Movie
bigRed_btn.onRelease = function  () {
    unloadMovie(slideshowHolder_mc);
    bigRed_btn._visible = false;
    bigBlue_btn._visible = true;
    txtMovieNotLoaded._visible = true;
}

**[COLOR=Blue]

In “Slideshow.swf”:

[/COLOR]**


**[COLOR=Blue] var delay:Number = 3000;
//-----------------------[/COLOR]**
xmlData = new XML();
xmlData.ignoreWhite = true;
xmlData.onLoad = loadXML;

function loadXML(loaded) {
    if (loaded) {
        xmlNode = this.firstChild;
        image = [];
        description = [];
        total = xmlNode.childNodes.length;
        for (i=0; i<total; i++) {
            image* = xmlNode.childNodes*.childNodes[0].firstChild.nodeValue;
            description* = xmlNode.childNodes*.childNodes[1].firstChild.nodeValue;
        }
        firstImage();
    } else {
        content = "file not loaded!";
    }
}

xmlData.load("images.xml");

// ///////////////////////////////////
listen = new Object();
listen.onKeyDown = function() {
    if (Key.getCode() == Key.LEFT) {
        prevImage();
    } else if (Key.getCode() == Key.RIGHT) {
        nextImage();
    }
};
Key.addListener(listen);
previous_mc.onRelease = function() {
    prevImage();
};
next_mc.onRelease = function() {
    nextImage();
};
// ///////////////////////////////////
p = 0;
this.onEnterFrame = function() {
    filesize = picture.getBytesTotal();
    loaded = picture.getBytesLoaded();
    preloader._visible = true;
    if (loaded != filesize) {
        preloader.preloadBar._xscale = 100*loaded/filesize;
    } else {
        preloader._visible = false;
        if (picture._alpha<100) {
            picture._alpha += 10;
            }
    }
};
var myInterval;
function nextImage() {
    p++;
    p %= image.length;
    if (loaded == filesize) {
        picture._alpha = 0;
        picture.loadMovie(image[p], 1);
        desc_txt.text = description[p];
        picture_num();
        clearInterval(myInterval);
        if (playing) {
            slideshow();
        }
    }
}
function prevImage() {
    clearInterval(myInterval);
    if (playing) {
        slideshow();
    }
    if (p>0) {
        p--;
    } else {
        p = image.length-1;
    }
    picture._alpha = 0;
    picture.loadMovie(image[p], 1);
    desc_txt.text = description[p];
    picture_num();
}
function firstImage() {
    if (loaded == filesize) {
        picture._alpha = 0;
        picture.loadMovie(image[0], 1);
        desc_txt.text = description[0];
        picture_num();
        clearInterval(myInterval);
        if (playing) {
            slideshow();
        }
    }
}
function picture_num() {
    current_pos = p+1;
    pos_txt.text = current_pos+"/"+total;
}
function slideshow() {
    myInterval = setInterval(pause_slideshow, delay);
    function pause_slideshow() {
        clearInterval(myInterval);
        nextImage();
    }
}
stop.tt.text = "STOP";
play.tt.text="PLAY"
playing = true
play.onPress = function(){
    playing = true
    nextImage()
    
    
}
play.onRelease =play.onReleaseOutside= function(){
    this.gotoAndStop("_disabled")
    this.enabled = false
}
stop.onPress = function(){
    playing = false
    play.enabled = true
    clearInterval(myInterval)
}

**[COLOR=Red]

But it is better if you look for the attachment files -->[/COLOR]**

**[COLOR=Red][COLOR=Blue]For troubleshooting purpose, here’s the .FLA of the slideshow.swf[/COLOR]. [COLOR=DarkRed]I omitted it in the previous attachment because it exceeded the maximum allowed size.[/COLOR]
[/COLOR]
**:beer2:

try using

clearInterval(slideshowHolder_mc.myInterval)

when you load/unload the slideshow in the btn event handlers

[quote=stringy;2357531]try using
ActionScript Code:
[LEFT][COLOR=#0000ff]clearInterval[/COLOR]COLOR=#000000[/COLOR]
[/LEFT]

when you load/unload the slideshow in the btn event handlers[/quote]

[COLOR=DarkRed]** Thanks for a speedy response… your truly a flash man… a life saver**[/COLOR]:sen:

This solution works fine, but I’m curious? Why attaching the clearInterval for both the buttons, [COLOR=DarkGreen]why not only for unload operation/event[/COLOR]?

My first solution is to use [COLOR=DarkGreen]_lockroot=true[/COLOR]. In the main timeline I added “[COLOR=DarkGreen]this.slideshowHolder_mc._lockroot = true[/COLOR];” because I’ve read that it helps prevent conflicts of the loaded movie into the parent movie, but it seems it only refers for the root and have nothing to do for correcting the lost syntax functionalities of external movies.

Could you please educate me and the rest. Could you provide us a link for better understanding [COLOR=DarkGreen]why external movies loses some of its functionalities when loaded inside another movie? And how to solution this?[/COLOR]

How about the [COLOR=DarkGreen]onEnterFrame[/COLOR] that sets the preloading bar inside the slideshow.swf, do I have to delete this also every time I unload the slideshow or delete it every time a new image appear? [COLOR=DarkGreen]When I should delete this.onEnterFrame function[/COLOR]?

By the way I also added this code to clear cache every time I loaded a movie. [COLOR=DarkGreen]Is this the proper way of clearing the cache?[/COLOR]

d = [COLOR=Blue]new Date[/COLOR]();
// always a uniques number
kill = d.[COLOR=Blue]getTime[/COLOR]();
slideshowHolder_mc.[COLOR=Blue]loadMovie[/COLOR]("slideshow.swf?kill"+kill);

Once again thank you professor…