We will build this function in a
moment. To help the user see what is happening, we set a Text component to provide a message about
the kind of media it is (Current Media is Image - .png, for example). In the same way, when an MP3
or FLV video is selected, we call the appropriate function (playSound or playVideo, respectively).
244
CHAPTER 12
Figure 12-12. The logFileDetails function
To control the sound, we first create a sound channel. When the user double-clicks an MP3, the
createSound function is called. This function creates a sound object and plays it through the sound
channel. When the sound needs to be stopped, the stopSound function is called (Figure 12-13).
245
FLEX AND AIR
Figure 12-13. Functions that control sound
The functions for playing an image or a video are shown in Figure 12-14.
Figure 12-14. Functions that display images and video
In the case of an image, sound is stopped (in case an MP3 was playing before this image was selected),
the video display is made invisible and stopped (in case a video was playing before), and the image is
loaded. In the case of a video, sound is stopped in case a sound file was playing, the video display is
made visible, and the video is loaded.
246
CHAPTER 12
9. If you are not using the MediaCenter-start file, add the ActionScript shown in Figures 12-9 to
12-14 now.
You will notice that you get a series of error messages when you first put this code in. This is because
our functions are often set to perform actions on components that we have not yet created.
Pages:
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172