Tag Archives: ActionScript 3

Wilhem! Game Template

I built this  game a couple years ago as a demo of coding skills for a client. It’s not a game so much as a template for building a more complex game.  And for laughs, there’s the  Wilhem scream built in as a sound effect.

How to play: Select a coin, select a square to move to…. or select another occupied square and watch your coin die.

The code is an example of well organized flexible OOP Action-script coding.  My general approach to building Flash applications  of any complexity is a home-rolled MVC set up, observer design pattern, and the use interfaces… for starters. The complexity of the Flash projects I was taking on in the late 2000s, demanded adopting a flexible code organization. The primary objective was not get it out the door, but rather to  build it so we can add bells/ whistles and pull them out on short notice – without starting over from scratch Here is the code for the game template.

Random Tile class

Here’s an Actionscript 3 class I wrote the places tiles on a grid – either randomly or in order, with no overlap, and allows for a tile free zone.

You can see it in action here.
[cc lang=”actionscript3″ nowrap=”true” width=”550″]
* coding by mike Connor – flashDeveloper@rocketnumber9.org
* randomly places tiles on a grid so that o not overlap and do not fall in dead tile zone
package utils
import flash.display.DisplayObject;

public class RandomTile
private var numOfRows:uint;
private var numOfCols:uint;
private var rowArray:Array;
private var tileArray:Array;
private var unplacedArray:Array = new Array();
private var _gridW:uint;
private var _gridH:uint;
private var _maginTop:uint;
private var _marginLeft:uint;
private var _deadTiles:Array = new Array();
private var _randomLayout:Boolean;

public function RandomTile(r:uint, col:uint, ta:Array, gridW:uint = 76, gridH:uint = 76,
maginTop:uint = 2, marginLeft:uint=1, randomLayout:Boolean= true, deadTile:Array = null)
rowArray = new Array();
_randomLayout = randomLayout;

numOfRows = r;
numOfCols = col;
tileArray = ta;
_gridW = gridW;
_gridH = gridH;
_maginTop =maginTop;
_marginLeft = marginLeft;
if (deadTile !=null) _deadTiles = deadTile;
if (numOfRows * numOfCols < (tileArray.length - _deadTiles.length)) { throw new Error("Error - too many tiles, not enough spaces"); } else { init(); } } private function init():void { for (var i:uint=0; i= numOfCols){
colCount = 0;

Debug.trace_msg(“DONE placeTiles in order”, Debug.DEBUG_VERBOSE);

private function placeTilesRandomly(arr:Array):void {
for (var i:uint = 0; i

Frustrating FireFox bug with ExtnernalInterface – resolved

Looks like I had a problem with my JavaScript. I need to add:
var swfDiv = document.getElementById(‘swfDiv’);

Checks out now in FireFox 3.5 mac, FireFox PC (version?), IE 8 on the pc.

[cc lang="JavaScript" nowrap="true" width="550"]


The original problem laid out here

Source file for this little test are here:

Thank you to Nikolai of FlashCodersNY