Moving Objects

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

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!! =)