PDA

View Full Version : Moving Objects



crewman747
July 27th, 2003, 08:40 PM
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

kode
July 27th, 2003, 09:24 PM
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:
on (keyPress "<Left>") {
instanceName._x -= 2;
}
on (keyPress "<Right>") {
instanceName._x += 2;
}
on (keyPress "<Up>") {
instanceName._y -= 2;
}
on (keyPress "<Down>") {
instanceName._y += 2;
}
2) Use a MovieClip symbol instead of a Button.

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