# 1009 error XML slideshow function

**URL:** <https://forum.kirupa.com/t/1009-error-xml-slideshow-function/314777>\
**Category:** flash\
**Created:** [October 8, 2010, 10:05am UTC](https://forum.kirupa.com/t/1009-error-xml-slideshow-function/314777 "2010-10-08T10:05:47Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![nasir1123](https://avatars.discourse-cdn.com/v4/letter/n/6bbea6/32.png) [@nasir1123](https://forum.kirupa.com/u/nasir1123)\
**Post date:** [October 8, 2010, 10:05am UTC](https://forum.kirupa.com/t/1009-error-xml-slideshow-function/314777/1 "2010-10-08T10:05:47Z")

</div>

Hello all, I am using this code for my XML slideshow.  
Problem is that I want to switch to the next frame after the last slide is loaded.  
Now I managed to do that, only Flash doesn’t like the code much and throws me a 1009 error.  
at \_07oktober2010\_fla::MainTimeline/switchSlide()  
at flash.utils::Timer/\_timerDispatch()  
at flash.utils::Timer/tick()

I made the cause bold. It’s probably because the function switchslide is not ended correctly or something. Any solutions? Thanks in advance!

// import tweener  
import caurina.transitions.Tweener;  
import flash.events.Event;

// delay between slides  
const TIMER\_DELAY:int = 2000;  
// fade time between slides  
const FADE\_TIME:int = 2;

// reference to the current slider container  
var currentContainer ![](http://forum.kirupa.com/uploads/kirupa/6360/ca9da2d415402cfa.gif)prite;  
// index of the current slide  
var intCurrentSlide:int = -1;  
// total slides  
var intSlideCount:int;  
// timer for switching slides  
var slideTimer:Timer;  
// slides holder  
var sprContainer1 ![](http://forum.kirupa.com/uploads/kirupa/6360/ca9da2d415402cfa.gif)prite;  
var sprContainer2 ![](http://forum.kirupa.com/uploads/kirupa/6360/ca9da2d415402cfa.gif)prite;  
// slides loader  
var slideLoader:Loader;  
// url to slideshow xml  
var strXMLPath ![](http://forum.kirupa.com/uploads/kirupa/6360/ca9da2d415402cfa.gif)tring = “slideshow.xml”;  
// slideshow xml loader  
var xmlLoader:URLLoader;  
// slideshow xml  
var xmlSlideshow:XML;

function init():void {  
// create new urlloader for xml file  
xmlLoader = new URLLoader();  
// add listener for complete event  
xmlLoader.addEventListener(Event.COMPLETE, onXMLLoadComplete);  
// load xml file  
xmlLoader.load(new URLRequest(strXMLPath));

```
// create new timer with delay from constant
slideTimer = new Timer(TIMER_DELAY);
// add event listener for timer event
slideTimer.addEventListener(TimerEvent.TIMER, switchSlide);

// create 2 container sprite which will hold the slides and
// add them to the masked movieclip
sprContainer1 = new Sprite();
sprContainer2 = new Sprite();
mcSlideHolder.addChild(sprContainer1);
mcSlideHolder.addChild(sprContainer2);

// keep a reference of the container which is currently
// in the front
currentContainer = sprContainer2;

```

}

function onXMLLoadComplete(e:Event):void {  
// create new xml with the received data  
xmlSlideshow = new XML(e.target.data);  
// get total slide count  
intSlideCount = xmlSlideshow…image.length();  
// switch the first slide without a delay  
switchSlide(null);  
}

function fadeSlideIn(e:Event):void {  
// add loaded slide from slide loader to the  
// current container  
currentContainer.addChild(slideLoader.content);  
// clear preloader text  
mcInfo.lbl\_loading.text = “”;  
// fade the current container in and start the slide timer  
// when the tween is finished  
Tweener.addTween(currentContainer, {alpha:1, time:FADE\_TIME, onComplete:function() { slideTimer.start(); }});  
}

function switchSlide(e:Event):void {  
// check, if the timer is running (needed for the  
// very first switch of the slide)  
if(slideTimer.running)  
slideTimer.stop();

```
// check if we have any slides left and increment
// current slide index
if(intCurrentSlide + 1 &lt; intSlideCount)
	intCurrentSlide++;
// if not, start function to go to next frame

```

\*\* else  
stopSlideshow();\*\*

```
// check which container is currently in the front and
// assign currentContainer to the one that's in the back with
// the old slide
if(currentContainer == sprContainer2)
	currentContainer = sprContainer1;
else
	currentContainer = sprContainer2;

// hide the old slide
currentContainer.alpha = 0;
// bring the old slide to the front
mcSlideHolder.swapChildren(sprContainer2, sprContainer1);

// create a new loader for the slide
slideLoader = new Loader();
// add event listener when slide is loaded
slideLoader.contentLoaderInfo.addEventListener(Eve nt.COMPLETE, fadeSlideIn);
// add event listener for the progress
slideLoader.contentLoaderInfo.addEventListener(Pro gressEvent.PROGRESS, showProgress);
// load the next slide
slideLoader.load(new URLRequest(xmlSlideshow..image[intCurrentSlide].@src));

// show description of the next slide
mcInfo.lbl_description.text = xmlSlideshow..image[intCurrentSlide].@desc;
// show current slide and total slides
mcInfo.lbl_count.text = (intCurrentSlide + 1) + " / " + intSlideCount + " Slides";

```

}  
\*\*  
function stopSlideshow():void {  
slideTimer.stop();  
gotoAndStop(2);  
}\*\*

function showProgress(e ![](http://forum.kirupa.com/uploads/kirupa/5115/373eb333a028f173.gif)rogressEvent):void {  
// show percentage of the bytes loaded from the current slide  
mcInfo.lbl\_loading.text = "Loading image " + Math.ceil(e.bytesLoaded \* 100 / e.bytesTotal) + “%”;  
}

// init slideshow  
init();
