Frame 1
tellTarget ("/Congratulations") {
stop();
};
numRows = "3";
numCols = "3";
numCells = numRows * numCols;
i = "1";
while (i < numCells) {
Set("pos" add i, i);
i = i + "1";
}
empty = numCells;
i = "1";
while (numCols >= i) {
Set("x" add i, getProperty("/p" add i, _x));
i = i + "1";
}
i = "1";
while (numRows >= i) {
Set("y" add i, getProperty("/p" add ("1" + ((i - "1") * numCols)), _y));
i = i + "1";
}
nextFrame();
Frame 3
call("Winner");
if (winner == "1") {
call("Shuffle");
tellTarget ("/Congratulations") {
gotoAndStop (1);
stop();
};
} else {
pos = eval ("pos" add clicked);
emptyRow = "1" + int((empty - "1") / numCols);
emptyCol = empty - ((emptyRow - "1") * numCols);
clickedRow = "1" + int((pos - "1") / numCols);
clickedCol = pos - ((clickedRow - "1") * numCols);
rowDiff = clickedRow - emptyRow;
colDiff = clickedCol - emptyCol;
if (rowDiff < "0") {
rowDiff = -rowDiff;
}
if (colDiff < "0") {
colDiff = -colDiff;
}
adjacent = (rowDiff + colDiff) == "1";
if (adjacent == "1") {
setProperty("/p" add clicked, _x , eval ("x" add emptyCol));
setProperty("/p" add clicked, _y , eval ("y" add emptyRow));
Set("pos" add clicked, empty);
empty = pos;
call("Winner");
if (winner == "1") {
tellTarget ("/Congratulations") {
play();
};
}
}
}
Frame 4
i = "1";
while (numCells >= i) {
Set("cell" add i, i);
i = i + "1";
}
i = "1";
while (numCells >= i) {
Set("random" add i, random("1000"));
i = i + "1";
}
lo = "1";
up = "9";
while (lo < up) {
i = lo;
j = lo;
while (i < up) {
if (eval ("random" add (i + "1")) < eval ("random" add i)) {
temp = eval ("random" add i);
Set("random" add i, eval ("random" add (i + "1")));
Set("random" add (i + "1"), temp);
temp = eval ("cell" add i);
Set("cell" add i, eval ("cell" add (i + "1")));
Set("cell" add (i + "1"), temp);
j = i;
}
i = i + "1";
}
up = j;
i = up;
while (lo < i) {
if (eval ("random" add i) < eval ("random" add (i - "1"))) {
temp = eval ("random" add i);
Set("random" add i, eval ("random" add (i - "1")));
Set("random" add (i - "1"), temp);
temp = eval ("cell" add i);
Set("cell" add i, eval ("cell" add (i - "1")));
Set("cell" add (i - "1"), temp);
j = i;
}
i = i - "1";
}
lo = j;
}
i = "1";
r = "1";
c = "1";
while (numCells >= i) {
piece = eval ("cell" add i);
if (piece == "9") {
empty = i;
} else {
Set("pos" add piece, i);
setProperty("/p" add piece, _x , eval ("x" add c));
setProperty("/p" add piece, _y , eval ("y" add r));
}
c = c + "1";
if (numCols < c) {
c = "1";
r = r + "1";
}
i = i + "1";
}
Frame 6
winner = "1";
i = "1";
while (i < numCells) {
if (eval ("pos" add i) <> i) {
winner = "0";
}
i = i + "1";
}
Symbol 3 Button
on (release) {
Set("/:clicked", "1");
call("/:Click");
}
Symbol 7 Button
on (release) {
Set("/:clicked", "2");
call("/:Click");
}
Symbol 11 Button
on (release) {
Set("/:clicked", "3");
call("/:Click");
}
Symbol 15 Button
on (release) {
Set("/:clicked", "4");
call("/:Click");
}
Symbol 19 Button
on (release) {
Set("/:clicked", "5");
call("/:Click");
}
Symbol 23 Button
on (release) {
Set("/:clicked", "6");
call("/:Click");
}
Symbol 27 Button
on (release) {
Set("/:clicked", "7");
call("/:Click");
}
Symbol 31 Button
on (release) {
Set("/:clicked", "8");
call("/:Click");
}
Symbol 39 MovieClip Frame 45
gotoAndPlay (35);