# Moving multiple items using onEnterFrame

**URL:** <https://forum.kirupa.com/t/moving-multiple-items-using-onenterframe/233059>\
**Category:** flash\
**Created:** [July 19, 2007, 7:39pm UTC](https://forum.kirupa.com/t/moving-multiple-items-using-onenterframe/233059 "2007-07-19T19:39:31Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![steve\_b](https://avatars.discourse-cdn.com/v4/letter/s/ee7513/32.png) [@steve\_b](https://forum.kirupa.com/u/steve_b)\
**Post date:** [July 19, 2007, 7:39pm UTC](https://forum.kirupa.com/t/moving-multiple-items-using-onenterframe/233059/1 "2007-07-19T19:39:31Z")

</div>

I am trying create to move objects (boxes, named box\_1, box\_2 etc) to positions on the stage (xPos\_1, xPos\_2 etc) using onEnterFrames. I can make all the boxes move individually, but I cant get them to move together. I am using the following code in an attempt to move 3 boxes.

If anyone can point me in the right direction it would be appreciated!

```php

while (k < 3) {

_root.onEnterFrame = function() {
    
        _root["box_"+k]._x -= 5;
        _root["box_"+k]._y -= 5;
        
        if (_root["box_"+k]._x <= _root["xPos_"+k]) {
            _root["box_"+k]._x = _root["xPos_"+k];
        }
        
        if (_root["box_"+k]._y <= yPos) {
            _root["box_"+k]._y = yPos;
        }
    
    }
k++;    
}

```
