# Problem with proper usage of removeActionListener ... need help

**URL:** <https://forum.kirupa.com/t/problem-with-proper-usage-of-removeactionlistener-need-help/323595>\
**Category:** flash\
**Created:** [July 8, 2011, 3:58pm UTC](https://forum.kirupa.com/t/problem-with-proper-usage-of-removeactionlistener-need-help/323595 "2011-07-08T15:58:36Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![interferential](https://avatars.discourse-cdn.com/v4/letter/i/58f4c7/32.png) [@interferential](https://forum.kirupa.com/u/interferential)\
**Post date:** [July 8, 2011, 3:58pm UTC](https://forum.kirupa.com/t/problem-with-proper-usage-of-removeactionlistener-need-help/323595/1 "2011-07-08T15:58:36Z")

</div>

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](http://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:

```auto
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.
