# OnEnterFrame Help

**URL:** <https://forum.kirupa.com/t/onenterframe-help/261340>\
**Category:** flash\
**Created:** [May 26, 2008, 5:57pm UTC](https://forum.kirupa.com/t/onenterframe-help/261340 "2008-05-26T17:57:57Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![sri\_dawg](https://avatars.discourse-cdn.com/v4/letter/s/e79b87/32.png) [@sri\_dawg](https://forum.kirupa.com/u/sri_dawg)\
**Post date:** [May 26, 2008, 5:57pm UTC](https://forum.kirupa.com/t/onenterframe-help/261340/1 "2008-05-26T17:57:57Z")

</div>

hey guys, first time posting here and a novice at actionscript. Basically im trying to build something like a carousel, but with using the keyboard arrow keys. If a user hits the left arrow key the onEnterFrame event should move to the next menu item and stop. The logic I used for this is if the x position of a movieclip is at 0, then set the speed to 0. Unfortunately what happens is that while most of the movieclips (menu items) stop, some trail a little off and end up having a lead on the others, leading to overlappings and such. The code is as follows:  
(note: all the movieclips (buttons) have linkage identifiers, and are attached to the stage)

var centerX:Number = Stage.width / 2;  
var speed:Number = 0  
var beginX= 0;

var begin:Boolean = true;

for(var i=1;i\<13;i++)

{  
var t = this.attachMovie(“button”+i,“b”+i,i+1);  
t.\_x = beginX += 35 ;  
t.\_y = 35;  
t.onEnterFrame = mover;  
}

function mover()  
{  
if (this.\_x == centerX && begin == false )  
{  
this.\_xscale = 150;  
this.\_yscale = 150;  
speed = 0;  
}  
else  
{  
this.\_xscale = 100;  
this.\_yscale = 100;  
}

```
this._x += speed;
if (this._x &gt; 420)
	this._x = 0;
else if (this._x &lt; 0)
	this._x = 420;

```

}  
var keyListener:Object = new Object();  
keyListener.onKeyDown = function() {  
switch (Key.getCode()) {  
case 39:  
begin = true;  
speed = 5;  
break;  
case 37:  
begin = true;  
speed = -5;  
break;  
}}  
keyListener.onKeyUp = function() {  
switch (Key.getCode()) {  
case 39:  
begin = false;  
break;  
case 37:  
begin = false;  
break;  
}}  
Key.addListener(keyListener);

---

<div class="post-metadata">

**Author:** ![sri\_dawg](https://avatars.discourse-cdn.com/v4/letter/s/e79b87/32.png) [@sri\_dawg](https://forum.kirupa.com/u/sri_dawg)\
**Post date:** [May 26, 2008, 6:40pm UTC](https://forum.kirupa.com/t/onenterframe-help/261340/2 "2008-05-26T18:40:22Z")

</div>

Come on guys…no suggestions at all??
