Once in its final position we add the components on the panel. The first component on the panel is the message bar at the top of the panel. This is a simple dynamic text object labelled “messages” and set to use a center aligned 24-point grey “serif” font. Below that we create a static text message that reads “Take how many?” I broke this into vector text and created a graphical symbol out of the text. Finally there are three buttons labelled “1,” “2,” and “3.” These three buttons are created the same way we created the "Start the Game" button. Simply type in the number. Break apart the number so you get a Flash object. Select the "Make Symbol" option to convert the object into a button symbol. Fill in the over and down keyframes with different colored versions of the number object. Finally, in the hit keyframe, create a solid box that covers the number.
Once all the components of the panel are visible, we need to make the three buttons do something. The code for the buttons is like the code that we used with the start game button. The one significant difference is that we are using a function that handles setting up all three buttons and we also need to be able to turn off the buttons. This code is simple enough as we simply call/remove the handler for each button by using the addEventListener or removeEventListener methods.
function startPanel(gm) {
gameMovie = gm;
gm.messages.text = "You go first!";
gm.one_btn.addEventListener("click", handleOneButton);
gm.two_btn.addEventListener("click", handleTwoButton);
gm.three_btn.addEventListener("click", handleThreeButton);
}
function stopPanel(gm) {
gm.one_btn.removeEventListener("click", handleOneButton);
gm.two_btn.removeEventListener("click", handleTwoButton);
gm.three_btn.removeEventListener("click", handleThreeButton);
}
The actual handlers for when the buttons are clicked are game-play related so will be covered in a later section once we start implementing the gameplay logic. Another function that we will need for the panel is a function to write the message bar text. While this is a very simple thing to do and could be done directly wherever the message needs to be set, I find calling a function that sets the message bar is a bit easier to understand, and adds some flexibility in the case that how messages are displayed changes in the future. Quite simply, this function takes the text passed to it and assigns that text to the dynamic text object we defined in the panel.
function setMessage(s) {
gameMovie.messages.text = s;
}
As the buttons that make up the user interface cover removal of gems, we need a way to remove gems. That will be covered next section.