Now that the coding is in place and the ColdFusion Component has been written, you can start to build the booking facility. This is the easiest part of the job. To build an interactive reservation facility in Flash MX 2004, follow these steps:
Open Flash MX 2004. When the application opens, change the canvas in the Property Inspector to 550 pixels wide by 480 pixels high. Set the background color to white?#FFFFFF?in the Property Inspector.
Insert three new layers in the timeline by clicking the Insert Layer button. Rename the layers, from the top layer down, Scripts, Buttons, Layouts, and Facilities. When finished, your screen should resemble that shown in Figure 13.7.
With the layers defined, it is time to incorporate the booking.as script into this movie and to stop the movie from looping.
Click once in frame 1 of the Scripts layer and press the F9 key to open the Actions panel. Type the following script into the text input area:
Close the Actions panel.
This line of code calls the booking.as file created earlier in Dreamweaver.
Add a new keyframe in frame 5 of the Scripts layer. Select the frame and open the Actions panel. Enter the following:
Close the Actions panel. The stop action is added to frame 5 to prevent the playback head from looping and reloading the code every time it arrives in frame 1 of the movie.
With the first frame of the movie "loading" the booking.as code and the playback head stopped on frame 5, you can now turn your attention to building the interface. The list of the facilities to be booked will appear in a pop-down menu box.
Those facilities will be pulled from the MySQL database by the booking.as script interacting with the ColdFusion MX Component and will automatically populate the menu. In this manner, you can add new facilities to the community center and only have to change the MySQL database. The changes made will appear in the menu. This menu is already built for you. The ComboBox component is the ideal solution for this task.
Drag a ComboBox component from the UI Components panel to frame 1 of the Facilities layer. When the ComboBox appears on the canvas, drag it to the upper-right corner of the canvas. Add a blank frame in frame 5 of the Facilities layer.
With the ComboBox component selected, give the instance the name of facilitiesList in the Property Inspector.
In the previous version of Flash, the ComboBox component would require you to point to a function handler to process the changes the user would make. This has changed with the recent release of Flash MX 2004.
Components in Flash MX 2004 borrow from modern coding frameworks in that they use an event-messaging infrastructure to broadcast any changes or selections that a user makes. Any object within your Flash application can listen in on any other component by adding itself to the component's list of objects to which it broadcasts. For example, if you click a button in one component and another is listening, the listening object will automatically be aware that the button was clicked and will process the results of the click.
Thus, when a user makes a selection, the component will broadcast the event, "Something was just selected!" to every object that is listening to that component. This method is very convenient for programmers. They can now create controller objects that respond to the components in your Flash movie and communicate the changes to the objects that work with your data. This is a loose explanation of the Model-View-Controller principle. An example of the event listener object can be found in the booking.as code.