Building the Base Grid
First, you you need to build the various interface elements that will enable the user to interact with this game, starting with the grid: a number of boxes (or cells) grouped together that will store the sounds you have in the Library.
NOTE
To make the project as flexible as possible, you will want to make everything but the static images build themselves dynamically. This allows you to add more sounds, or change the look of your instrument, and have it apply to the entire movie easily.
Start by declaring all the variables. Open soundtoy_start.fla from the downloadable files for this article.
Click on the script layer and open the Actions panel.
On Frame 1, add the following script to declare the variables. Note that you are scripting using the Actions panel in what used to be known as Expert mode in previous versions of Flash.
Save your work.
The Timeline of the main movie has four layers: background, text, risingsun, and script (see Figure 2). You'll use the script layer to store your actions. The bottom three layers contain all the static background graphics of the game, such as the geisha, the rising sun, and the haiku text.
NOTE
You can also copy and paste each of the listings in this article from the downloadable files.
Listing 01
onLoad = function(){ //constants _global.ROWS = 4; _global.COLUMNS = 5; _global.BOXWIDTH = 100; _global.BOXHEIGHT = 40; _global.DEFAULTBOXALPHA = 30; _global.SPEED = 5; //variables var x,y :Number = 0; var soundNum :Number = 0; }
Here, you have written an initialization function so that you can build your project dynamically.
By associating this with the onLoad movie clip method, you can make sure that the construction happens on the first frame of the .swf file and is transparent to the user.
Following that, you insert the variables that will define the parameters of the grid, such as width, height, alpha value, and playback motion. Note that these values are constant and should not be changed.
Defining these variables as global will make them accessible to every timeline in your movie, and prevent you from having to refer to_root or _parent.
These variables are defined as being of the type Number, which will prevent them from being filled with a different type of value (doing so will return an error).