# Moving Objects

**URL:** <https://forum.kirupa.com/t/moving-objects/26895>\
**Category:** programming\
**Created:** [July 28, 2003, 12:40am UTC](https://forum.kirupa.com/t/moving-objects/26895 "2003-07-28T00:40:22Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![crewman747](https://avatars.discourse-cdn.com/v4/letter/c/85e7bf/32.png) [@crewman747](https://forum.kirupa.com/u/crewman747)\
**Post date:** [July 28, 2003, 12:40am UTC](https://forum.kirupa.com/t/moving-objects/26895/1 "2003-07-28T00:40:22Z")

</div>

I have a square that is a button symbol. There is a cirlce that is a movie clip symbol. I assigned the following actions to the button

on (keyPress “Left”) {  
currentX = this.\_x;  
this.\_x = currentX - 2;

}  
on (keyPress “Right”) {  
currentX = this.\_x;  
this.\_x = currentX + 2;

}  
on (keyPress “Up”) {  
currentY = this.\_y;  
this.\_y = currentY - 2;

}  
on (keyPress “Down”) {  
currentY = this.\_y;  
this.\_y = currentY + 2;

}

For some reason, the square and the circle both move. Does anyone know why this happens. If so, how can i just make the block move and not the circle.

note: the \<\> symbols are not put surroundin the key names

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex011/uploads/kirupa/original/3X/6/2/621e5c11736f46532526e61be85940af4230f3e5.png) [@system](https://forum.kirupa.com/u/system)\
**Post date:** [July 28, 2003, 1:24am UTC](https://forum.kirupa.com/t/moving-objects/26895/2 "2003-07-28T01:24:24Z")

</div>

Actions in Button symbols are referenced to the timeline, that’s why the whole thing moves. :-\

There are three options:

1. Use the instance name of your Button instead of _this_:  
[AS]on (keyPress “\<Left\>”) {  
instanceName.\_x -= 2;  
}  
on (keyPress “\<Right\>”) {  
instanceName.\_x += 2;  
}  
on (keyPress “\<Up\>”) {  
instanceName.\_y -= 2;  
}  
on (keyPress “\<Down\>”) {  
instanceName.\_y += 2;  
}[/AS]

2. Use a MovieClip symbol instead of a Button.

3. Put your code in the Frame Actions.  
[AS]instanceName.onKeyDown = function() {  
this.\_x += (Key.isDown(39)-Key.isDown(37))\*2;  
this.\_y += (Key.isDown(40)-Key.isDown(38))\*2;  
};  
Key.addListener(instanceName);[/AS]  
By the way, welcome to kirupa forum!! =)
