PDA

View Full Version : Stuck with Error #1009



DrewFulton
October 19th, 2008, 08:47 PM
I am new to Flash CS3 and ActionScript 3.0 but have been making good progress I think. However, I am stuck with an error at the moment and after and hour of testing haven't come up with a solution.

The error reads:
TypeError: Error #1009: Cannot access a property or method of a null object reference.
at slideshow_fla::mc_slideshow_3/loadThumbs()
at slideshow_fla::mc_slideshow_3/slideshow_fla::frame1()

I am posting a couple snippets of code here but the whole project is attached.

Basically, I have cobbled a couple different projects together in an attempt to make a slideshow with scrolling thumbnails at the bottom and a slideshow at the top. I haven't added in the ability to click on a thumbnail and change the top image yet but thats next. Right now I am just trying to get the thumbnails to show up and scroll with onmouseovers which will eventually be converted to buttons instead.

Anyway, this is the section of loadThumbs() mentioned in the above error.

I can comment out one line that removes the error but then nothing happens and that is noted below.



function loadThumbs():void {

//check here to see if the thumbLoader is null or not. If its not null, that means a load operation is in progress
//so we need to kill that load using the unload method, remove its event listeners and set that instance of the loader object
//to null
if (thumbLoader!=null) {
thumbLoader.contentLoaderInfo.removeEventListener( Event.INIT, thumbLoaded);
thumbLoader.close();
thumbLoader = null;
}
thumbLoader = new Loader();
thumbLoader.contentLoaderInfo.addEventListener(Eve nt.INIT, thumbLoaded);

thumbLoader.load(new URLRequest( "images/thumb/" + xmlSlideshow..image[i].@filename)); //COMMENT OUT THIS LINE AND NO ERROR!
i++; //increment through the thumbnails array
}

Thanks for any and all help.

Digitalosophy
October 19th, 2008, 10:44 PM
Where are you creating your i counter?

DrewFulton
October 19th, 2008, 11:24 PM
i is declared as an integer early on. The counter is used in the thumbLoaded() function called when thumbLoader is Initiated in the code above.

Below is the full code for the thumbLoaded() function



function thumbLoaded(event:Event):void {
// Set up dimensions for thumbnail panel dynamically.
if (intthumb_current==0) {
//scroller pane specfic setup
intscrollPaneWidth = thumbLoader.content.width*intthumb_vis+(intpadding *(intthumb_vis-1));//mask
intscrollTrackWidth = thumbLoader.content.width*intslide_total+(intpaddi ng*(intslide_total-1));//scrolltrack
intscrollPaneHeight = thumbLoader.content.height;
constructScroller();
}

child = new MovieClip();
//dynamic var to give us and index position, meaning we can access the associated large image
//residing in this XML node.
child.intthumb_current = intthumb_current++;
child.addChild(thumbLoader);
//event listeners for rolling over and clicking thumbnails
child.addEventListener(MouseEvent.MOUSE_OVER, overThumb);
child.addEventListener(MouseEvent.MOUSE_OUT, offThumb);
// child.addEventListener(MouseEvent.CLICK, switchSlide(intthumb_current));
//add the content to the thumbs track
holder_mc.addChild(child);
TweenLite.from(child, 3, {alpha:0});//alpha in the thumbnails
//shuffle the content along, so we get a nice spread of thumbnails
child.x = intchangex; //set the x pos of the thumb to the intchangex var
intchangex = intchangex + thumbLoader.content.width + intpadding;//increments thumb x value in thumbs track + adds in any intpadding.
//child.buttonMode = true;//uncomment if you want a hand cursor
//null the thumbloader
thumbLoader = null;

if (i < intslide_total) {
loadThumbs();//create loop
}
if (i == intslide_total) {
//add the scroll listeners when we have content and its ready to scroll
//this if test below checks to see if there are enough thumbnails to actually need the scroll listeners
if (child.width * i + (intpadding*(i-1)) > intscrollPaneWidth) {
addScrollListeners();
}
}
}



Drew

sekasi
October 19th, 2008, 11:35 PM
200 bucks says you're trying to access the XML before it's loaded.

try tracing the two functions. One where the error is and one where the xml is being set and see which one comes first and see if you owe me money :P

DrewFulton
October 19th, 2008, 11:45 PM
Well, I would have taken that bet... oops. I put the loadthumbs() call in a function that runs after the XML Loads and bingo.

No more errors. The thumbnails aren't showing up as they are supposed to, but at least no more errors.

Anyone want to look at the larger issues for me?

Drew