Source Code and Comments

We present the AIR for Android version of our Traffic Lights Game. We provide here complete source code for our TrafficLightsFM Android app that you can download and install from the Android Market. Open the Android Market on your phone, search for flashandmath, and locate TrafficLightsFM on our apps list. Or access Android Market and the list of our apps directly   from this link.

Traffic Lights is a very challenging game. It is a variation and extension of the classic "Lights Out " puzzle. The goal of the game is to click on the lights until you can get them all to be green. Clicking on a light will change its color, but also the color of all of the neighbor lights attached to it. The light colors cycle through green, yellow, and red, just like a traffic light. The puzzles are made from a grid of lights (of varying sizes depending on the settings) which are connected in randomized configurations.


Working with the Source Files

The zip file contains TrafficLightsFM.fla file and a folder of custom AS3 classes: com -> flashandmath ->*. TrafficLightsFM.fla file was created from AIR for Android template that becomes available in your Flash CS5 after you download and install AIR for Android Extension for Flash CS5 from the Adobe site. See our Android example AIR for Android Application KaleidoscopeFM - Source Code for useful links how to get started with AIR for Android in Flash CS5.

After you open TrafficLightsFM.fla in Flash CS5, you must enter AIR Android Settings and set those again in order to be able to play with the application and have it install on your phone for testing purposes. In this case, the settings are simple.

Under General, make sure the app is set to Portrait mode.

Under Deployment, create or enter your p12 certificate. Then choose Android deployment type and After publishing settings. With our phone-computer setup, we worked with Device Release, Install application..., and Launch application checked.

Under Permissions, nothing. This app does not require any permissions.

About the Code

Building the AIR Android version of this game was very straightforward after having built the web version, illustrating the ease of targeting multiple devices with one ActionScript code base. We simply needed to reposition some elements on the stage and create a different Help page to make up for the reduced screen size. Almost all of the core code is identical to the web version.

In this game, the player clicks on the lights to change their color, with the goal of getting them all to be green. Designing this game for a touch screen requires some care so that each light has a large enough hit area to register touch events. The lights are not very large, so we have added an invisible (alpha = 0) disk shape on top of each light which is larger than the actual light. We also redesigned all of the buttons to have a larger touch-friendly size.

Because of the reduced screen size we have put the buttons on a panel which must be opened by clicking on the Menu key of Android devices. Adding the listeners for a Menu key press is a simple matter, which we have described previously in our AIR for Android Example Rolling Cubes 3D Puzzle.

See our earlier post Traffic Lights - Web Version for more comments about the graph algorithm used in the building of this puzzle.

Enjoy the game!

This TrafficLightsFM app was written by Dan Gries of flashandmath.

Back to AIR for Android              Back to Flash and Math Home

We welcome your comments, suggestions, and contributions. Click the Contact Us link below and email one of us.

Adobe®, Flash®, ActionScript®, Flex® are registered trademarks of Adobe Systems Incorporated.