# Swap Depths +Movement

**URL:** <https://forum.kirupa.com/t/swap-depths-movement/311029>\
**Category:** flash\
**Created:** [June 25, 2010, 2:00pm UTC](https://forum.kirupa.com/t/swap-depths-movement/311029 "2010-06-25T14:00:24Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jephz](https://avatars.discourse-cdn.com/v4/letter/j/58956e/32.png) [@Jephz](https://forum.kirupa.com/u/Jephz)\
**Post date:** [June 25, 2010, 2:00pm UTC](https://forum.kirupa.com/t/swap-depths-movement/311029/1 "2010-06-25T14:00:24Z")

</div>

Hey, this is my first time working with swap depths so bare with me.

I’m trying to find a way to integrate swap depths with map scrolling. Here is my current code:

SWF:  
[www.swfcabin.com/open/127746933](http://www.swfcabin.com/open/127746933)

```auto

var mapItem:Array = new Array(_root.tree1, _root.building1, _root.keith,_root.shinru);

mapControl = function () {
	_root.player.swapDepths(_root.player._y);
	for (var i:Number = 0; i<mapItem.length; i++) {
		if (mapItem*.hitTest(_root.player)) {
			_root.mapItem*.swapDepths(_root.mapItem*._y);
		}
		if (_root.player.hitTest(_root.boundLeft)) {
			mapItem*._x += _root.moveSpeed;
			_root.player._x += moveSpeed
		}
		if (_root.player.hitTest(_root.boundRight)) {
			mapItem*._x -= _root.moveSpeed;
			_root.player._x -= moveSpeed
		}
		
	}
};

```

The problem lies within the fact that the bounds are pushing away the player too fast for Flash to finish cycling through the array of items.

Please, any help is appreciated as I have thought of everything I could.

PS: I’m a novice when it comes to working with depth control, so feel free to post **constructive** criticism.

-Jephz
