# Conquering ENTER\_FRAME :)

**URL:** <https://forum.kirupa.com/t/conquering-enter-frame/280238>\
**Category:** Uncategorized\
**Created:** [January 24, 2009, 8:09pm UTC](https://forum.kirupa.com/t/conquering-enter-frame/280238 "2009-01-24T20:09:21Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![lope](https://avatars.discourse-cdn.com/v4/letter/l/43a26b/32.png) [@lope](https://forum.kirupa.com/u/lope)\
**Post date:** [January 24, 2009, 8:09pm UTC](https://forum.kirupa.com/t/conquering-enter-frame/280238/1 "2009-01-24T20:09:21Z")

</div>

\*\*touching \*\*is a Boolean which is declared as **false** ;  
it becomes true in here:

```php
mc.addEventListener(MouseEvent.MOUSE_OVER, onRollOver);
      function onRollOver(e:MouseEvent):void {
      touching = true;
}

```

and then false again in here:

```php
mc.addEventListener(MouseEvent.MOUSE_OUT, onRollOut);
      function onRollOut(e:MouseEvent):void {
      touching = false;
}

```

first of all, i wanted to say it like this:

```php
if (touching == true) {
addEventListener(Event.ENTER_FRAME, scrollMouse);
function scrollMouse(e:Event):void {
        TweenLite.to(container, 1, {x:((stage.stageWidth - container.width)/stage.stageWidth * mouseX)});
   }
}
if (touching == false) {
removeEventListener(Event.ENTER_FRAME, scrollMouse);
}

```

But it doesnt work, the listener is never added, dont understand why…

it WORKS like this:

```php
addEventListener(Event.ENTER_FRAME, scrollMouse);
function scrollMouse(e:Event):void {
if (touching == true) {
        TweenLite.to(container, 1, {x:((stage.stageWidth - container.width)/stage.stageWidth * mouseX)});
   }
}
if (touching == false) {
}

```

But it defeats a purpose of adding/removing event listener when not necessary, especially ENTER\_FRAME.

how can i make this work so that i add that listener only when i want and remove it accordingly?  
i dont want to have ENTER\_FRAME on my neck all the time…
