Tic Tac Toe Flash Lite 2.0 - inside view

This page reveals the implementation secrets of the tic tac toe application in Flash Lite 2.0.

 

Game logic

The Flash Lite 2.0 version is a port of the "non-lite" flash implementation. Original version did not have reach audio and video clips included and looked quite differently. That means that all new graphics elements appeared immediately and control flow in action script was linear with no delays or interruptions. Here is the original version.

Using setInterval to delay execution of Action Script

// Original version
function pcturn() {
	// Calculate position for computer piece
	...
	// Put new piece on the screen.
	// Happens with no delays, because there is no sound attached
	duplicateMovieClip("oh", "oh"+tmp, tmp);
	_root["oh"+tmp]._x = _root["rc"+tmp]._x;
	_root["oh"+tmp]._y = _root["rc"+tmp]._y;
	 
	// Call findWinner to check if the game is over
	findwinner(false);
}

// Updated version
function pcturn() {
	// Calculate position for computer piece
	...
	// Put new piece on the screen.
	// Now it takes some time because of no sound
	duplicateMovieClip("oh", "oh"+tmp, tmp);
	_root["oh"+tmp]._x = _root["rc"+tmp]._x;
	_root["oh"+tmp]._y = _root["rc"+tmp]._y;
	 
	// Can not call findWinner immediately, because it can trigger
	// the sound and animation, while current still playing
	//findwinner(false);
	
	// Delay call to findWinner by 2 seconds with the help of setInterval
	ifalse = setInterval(findwinner, 2000, false);
}

Working with the dynamic sound

The following function allows dynamically trigger sound from the action script. It creates new sound object attaches sound to this object and starts playback. Sound clips that are used in the game imported to library in FLA file. Each sound object in the library has enabled export for action script property and export name assigned. This export name is passed to attachSound as idname variable.

  function mysound(idname) 
  {
  mysoundobj = new Sound(this);
  mysoundobj.attachSound(idname);
  mysoundobj.start();
  }