I took an existing Tic Tac Toe game in Actionscript 2, and I am trying to modify it. The modifications are mostly animation-related.
The original version of the game was only a single frame. In order to add the animations I wanted, I had to space things out, which predictably has caused problems. Let’s focus on one of those problems.
Let us try to let the computer win the game. Computer wins game > game resets > computer has first turn > everything is fine. Every time the computer makes a move, an animation plays.
On the third game, the animation plays twice. Not on the first game, not on the second game, but on the third game the animation of placing the playing piece plays twice, with seemingly 1 frame delay.
The following body of code is a section of the whole code. I believe this is what is causing the problem. I don’t like having it onEnterFrame, but I tried everything else I could think of and these ‘if statements’ wouldn’t work at all unless they were in an onEnterFrame. This function repeats continuously until the game is reset, but doesn’t cause an animation problem until the third game. tmp is the position that the computer has moved to on the board.
onEnterFrame = function () {
if (tmp == 11) {
_root.armcontainer1.gotoAndStop(2);
_root.rc11.enabled = false;
trace("tmp");
}
};
If I can make this code work without having it be onEnterFrame, I think that could solve the problem, but this is the only way I’ve gotten this section of code to run at all.
If tmp == 11, the following code runs continuously. I want it to run only once per turn. So I’d like to use something other than onEnterFrame. However, I can’t get any other method to work.
onEnterFrame = function () {
if (tmp == 11) {
_root.armcontainer1.gotoAndStop(2);
_root.rc11.enabled = false;
trace ("tmp");
}
};
The code above works, and traces “tmp”, but runs continuously, which I don’t want.
I’ve tried other things below, which do not work:
tmp changes every time the computer moves. It can be 9 different values: 11, 12, 13, 21, 22, 23, 31, 32, 33. It corresponds to spaces on the tic tac toe board.
tmp is set in quite a few places in the code. There are 4 difficulty levels in the game, and each has different code that sets tmp. There is one function which sets tmp which runs for all 4 difficulty levels. That function is:
If tmp is set to 11 in the pcstrategy function, the trace should work. This suggests that tmp is not being set to 11. Maybe trace tmp at the end of the function and see what you get.