# ENTER FRAME event goes to every instance. why?

**URL:** <https://forum.kirupa.com/t/enter-frame-event-goes-to-every-instance-why/287047>\
**Category:** flash\
**Created:** [April 25, 2009, 12:42am UTC](https://forum.kirupa.com/t/enter-frame-event-goes-to-every-instance-why/287047 "2009-04-25T00:42:50Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![miwoj](https://avatars.discourse-cdn.com/v4/letter/m/6bbea6/32.png) [@miwoj](https://forum.kirupa.com/u/miwoj)\
**Post date:** [April 25, 2009, 12:42am UTC](https://forum.kirupa.com/t/enter-frame-event-goes-to-every-instance-why/287047/1 "2009-04-25T00:42:50Z")

</div>

my first post here. im kinda new to flash and actionscript.

i have this problem, i created couple instances of movieclip with some simple animation inside, want it to animate when mouse is over, and animate backwards when mouse is out.

so i have this code:

```auto

var goForward:Boolean = false;
	
box1.addEventListener(MouseEvent.MOUSE_OVER, boxOn);
box1.addEventListener(MouseEvent.MOUSE_OUT, boxOff);

box2.addEventListener(MouseEvent.MOUSE_OVER, boxOn);
box2.addEventListener(MouseEvent.MOUSE_OUT, boxOff);	
	
box1.addEventListener(Event.ENTER_FRAME, animate);
box2.addEventListener(Event.ENTER_FRAME, animate);

function boxOn(e:Event)
{
	goForward = true;
}

function boxOff(e:Event)
{
	goForward = false;
}

function animate(e:Event)
{
	trace("TARGET:"+e.target.name);
	if (goForward)	e.target.nextFrame();
	if (!goForward) e.target.prevFrame();
}

```

but when i mouse over one of instances, both of them are animating at the same time  
trace target name gives me box1,box2,box1,box2,box1,box2…

i managed to make it better by making

```auto

var goForward:Boolean = false;
	
box1.addEventListener(MouseEvent.MOUSE_OVER, boxOn);
box1.addEventListener(MouseEvent.MOUSE_OUT, boxOff);

box2.addEventListener(MouseEvent.MOUSE_OVER, boxOn);
box2.addEventListener(MouseEvent.MOUSE_OUT, boxOff);	
	
//box1.addEventListener(Event.ENTER_FRAME, animate);
//box2.addEventListener(Event.ENTER_FRAME, animate);
	
function animate(e:Event)
{
	trace("TARGET:"+e.target.name);
	if (goForward)	e.target.nextFrame();
	if (!goForward) e.target.prevFrame();
		
	if (e.target.currentFrame == 1) 
	{
		e.target.removeEventListener(Event.ENTER_FRAME, animate);
	}
}
	
function boxOn(e:Event)
{
	goForward = true;
	e.target.addEventListener(Event.ENTER_FRAME, animate);
}

	
function boxOff(e:Event)
{
	goForward = false;
}

```

it works better, only one instance move, but if i move mouse over second instance before first one finish moving back to the first frame (and remove listener), again both instances animate together, like they are using the same timeline.

what do i do wrong?
