It's raining discs

Then add the other function: this function has two arguments: the column where we are going to place the disc, and the player who is placing it.

The function will be executed only after checking the column is a legal one, so we assume we will find at least an empty space.

It updates the game field and returns the row where the disc is going to be placed.

public function firstFreeRow(column:uint,player:uint):int {
for (var i:uint=0; i<6; i++) {
if (gameField[i][column]!=0) {
return i-1;

While possibleColumns scans all columns, firstFreeRow scans all rows

for (var i:uint=0; i<6; i++) { ... }

for loop to go through all six rows, from top to bottom.

if (gameField[i][column]!=0) { ... }

Get Flash Game Development by Example now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.