PDA

View Full Version : Unload scroller returns error



felipegm
March 10th, 2010, 10:13 AM
I'm using a scroller with the bellow code:



//scroller

function scroller():void {
import com.greensock.*;
import com.greensock.easing.*;

var yOffset:Number;
var yMin:Number = 0;
var yMax:Number = sb.track.height - sb.thumb.height;

sb.thumb.addEventListener(MouseEvent.MOUSE_DOWN, thumbDown);
stage.addEventListener(MouseEvent.MOUSE_UP, thumbUp);
sb.thumb.buttonMode = true;
function thumbDown(e:MouseEvent):void {
stage.addEventListener(MouseEvent.MOUSE_MOVE, thumbMove);
yOffset = mouseY - sb.thumb.y;
}

function thumbUp(e:MouseEvent):void {
stage.removeEventListener(MouseEvent.MOUSE_MOVE, thumbMove);
}



function thumbMove(e:MouseEvent):void {
sb.thumb.y = mouseY - yOffset;
if (sb.thumb.y <= yMin) {
sb.thumb.y = yMin;
}
if (sb.thumb.y >= yMax) {
sb.thumb.y = yMax;
}
var sp:Number = sb.thumb.y / yMax;
TweenLite.to(content.content,1, {y:(-sp*(content.content.height-content.masker.height))});
e.updateAfterEvent();
}
}

stop();



the scroller and it's code is inside a swf that's being loaded into the main movie.
When I unload the swf that contains the scroller, the listeners are still active to the stage and/or the scroller component.

the error I'm getting is:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
at MethodInfo-1094()

How can I remove the listeners so the error does not happens? I noticed that after unloading the swf, if I click anywhere the stage, the error happens.

Thanks

IQAndreas
March 10th, 2010, 10:26 AM
Another day, another #1009 error:

TypeError: Error #1009: Cannot access a property or method of a null object reference.
Hands down, with no doubt possible in anyone's mind the absolute #1 error. There are 2 possible causes:


Error #1009 when preloading another SWF:
http://www.kirupa.com/forum/showpost...10&postcount=2 (http://www.kirupa.com/forum/showpost.php?p=2495410&postcount=2)
http://www.kirupa.com/forum/showthread.php?t=330677
http://www.kirupa.com/forum/showthread.php?p=2500293
http://www.kirupa.com/forum/showthread.php?t=333092
Error #1009 in general:
http://www.kirupa.com/forum/showpost...21&postcount=2 (http://www.kirupa.com/forum/showpost.php?p=2500521&postcount=2)

Taken from http://iqandreas.blogspot.com/2009/09/most-common-flash-questions-as3-faq.html

In your code I see three different references to "stage" which are the likely cause of the error.