Hello kirupa forum,
I’m still a beginner with AS, so please be kind, as this will be surely very obvious to you
I’m using this fancy scrollbox code for scrolling dynamic text loaded from text file using TweenMax. First of all - all credits go to greensock.com - I’m just trying to utilize this for my purpose.
So I have maintimeline with MC in one frame called mc_1.
In mc_1 i have this code for loading external text and scrolling it:
import com.greensock.TweenMax;
import fl.motion.easing.*;
stage.scaleMode = StageScaleMode.NO_SCALE;
slideBar.ruler.buttonMode=true;
function loadText():void {
var txtLoader:URLLoader = new URLLoader();
txtLoader.addEventListener(Event.COMPLETE, onLoaded);
content.autoSize = TextFieldAutoSize.LEFT;
txtLoader.load(new URLRequest("info.txt"));
removeEventListener(Event.COMPLETE, onLoaded);
function onLoaded(e:Event):void {
content.text = txtLoader.data;
if (content.height < slideBar.track.height) {
slideBar.alpha = 0;
} else if (content.height > slideBar.track.height) {
slideBar.alpha = 1;
slideBar.ruler.y = yMin;
content.y = masker.y;
}
}
}
loadText();
var yOffset:Number;
var yMin:Number = 0;
var yMax:Number = slideBar.track.height - slideBar.ruler.height;
slideBar.ruler.addEventListener(MouseEvent.MOUSE_DOWN, thumbDown);
stage.addEventListener(MouseEvent.MOUSE_UP, thumbUp);
function thumbDown(e:MouseEvent):void {
stage.addEventListener(MouseEvent.MOUSE_MOVE, thumbMove);
yOffset = mouseY - slideBar.ruler.y;
}
function thumbUp(e:MouseEvent):void {
stage.removeEventListener(MouseEvent.MOUSE_MOVE, thumbMove);
}
function thumbMove(e:MouseEvent):void {
slideBar.ruler.y = mouseY - yOffset;
if (slideBar.ruler.y <= yMin) {
slideBar.ruler.y = yMin;
}
if (slideBar.ruler.y >= yMax) {
slideBar.ruler.y = yMax;
}
var sp:Number = slideBar.ruler.y / yMax;
TweenMax.to(content, 1, {y:(-sp*(content.height - masker.height)), ease:Back.easeOut});
e.updateAfterEvent();
}
Now this works all well, but everytime I try to navigate to some other frame with some other mc (mc_2, mc_3 ), this EventListener :
stage.addEventListener(MouseEvent.MOUSE_UP, thumbUp);
is getting invoked, but produce an error as thumbUp function is declared in mc_1.
How to properly remove this EventListener , so that it still fullfill its job (which is: stop scrolling the text, when I unclick my mouse), but do not throw an TypeError#1009, when I try to navigate somewhere else (it does not break my movie, but still I’d like to build clean web).
Thank you for your answers ,
J.