in black and white
Main menu
Share a book About us Home
Biology Business Chemistry Computers Culture Economics Fiction Games Guide History Management Mathematical Medicine Mental Fitnes Physics Psychology Scince Sport Technics

macromedia flash mx - Reinhardt R.

Reinhardt R., Lott J macromedia flash mx - John Wiley & Sons, 2004. - 987 p.
ISBN 0-7645-4354-7
Download (direct link): macromediaflash2004.pdf
Previous << 1 .. 269 270 271 272 273 274 < 275 > 276 277 278 279 280 281 .. 419 >> Next

Lines 8 and 9 apply the transformObjects to the appropriate Sound objects.
Line 10 forces a faster update of the sound transformations, using the
updateAfterEvent() function.
When you are finished typing the code, press Ctrl+T or ^+T to check for any syntax errors.
Listing 23-9: Defining the onMouseMove() Handler for the Movie
1. this.onMouseMove = function() {
2. var nMouseX:Number = this._xmouse;
3. var nPercent:Number = (nMouseX/Stage.width)*100;
4. oLeftProps.ll = 100 - nPercent;
5. oLeftProps.rr = 100 - nPercent;
6. oRightProps.ll = nPercent;
Chapter 23 ¦ The Sound Class 595
7. oRightProps.rr = nPercent;
8. sndLeft.setTransform(oLeftProps);
9. sndRight.setTransform(oRightProps);
10. updateAfterEvent();
11. };
5. Now you’re ready to test your code. Save your Flash document as Sound_400.fla and test the movie using Control Î Test Movie (Ctrl+Enter or ^+Enter). Move the mouse to the left; you should hear the atmospheres_1.mp3 file playing in both speakers. As you move it away from the left edge, the sound should fade out, replaced with the sound of
On the You can view the completed Flash document, Sound_400.fla, on the book's CD-ROM.
This file, located in the ch23 folder, includes ActionScript that manipulates the rl and lr properties of the transformObjects, so that both channels of one sound will play in either the left or right speaker, adding to the depth perception of the sounds!
One of the more practical uses of the onSoundComplete() event handler for Sound objects is the capability to cycle MP3 playlists. In this section, you learn how to add this type of functionality to one of the exercise files you completed earlier in this section. Here’s the overview of the steps you need to do.
1. Create a list of MP3 file URLs. Store these values in an array. The array is created by a function named initSongList().
2. Modify the loadFile() method to play the first sound URL in the array if the tURL text field is empty. This URL is also removed from the array, so the next time the loadFile() method is called, a new URL will be used.
3. Modify the loadFile() method to trigger itself when a sound in the playlist has finished playing.
Now that you have a general idea about the process, you’re ready to build the Flash document.
On the - Before you begin this exercise, make a copy of the Sound_500_starter.fla, dog.mp3,
1. Open the starter file. This document contains a fully functional interface to load and play MP3 files. Save this document as Sound_500.fla.
2. Select frame 1 of the actions layer and open the Actions panel (F9). At the end of the existing actions list, add the following function and action. This function defines the array containing the URLs to the MP3 files. You can list http:// URLs of your own, or copy other MP3 files into the folder in which you saved your Flash document in Step 1
Making a Looping Playlist
cat.mp3, duck.mp3, and bird.mp3 files from the ch23 folder of this book's CD-ROM.
596 Part VI ¦ The Audio and Video Classes
Once the initSongList() function is defined, it is invoked when the movie starts. You will also use the initSongList() l ater, in the loadFile() function modifications.
function initSongList():Void {
aSongs = ["dog.mp3", "cat.mp3", "duck.mp3", "bird.mp3"];
var aSongs:Array; initSongList();
3. Now you define a function to check the content of the tURL field. If it is empty (that is, the user did not type any text into it), the function returns the URL of the first file in the array, and also removes that URL from the array using the shift() method. After the initSongList(); action from Step 2, add the following code:
function checkField():String { if(tURL.text != ""){ return tURL.text;
} else {
if (aSongs.length == 0) { initSongList();
return aSongs.shift().toString();
4. The last step is to change the loadFile() and onSoundComplete() methods to make use of the two functions you created in Steps 2 and 3. Add (or modify) the following lines of code displayed in bold type. The loadFile() method is called in the onSoundComplete() event handler to initiate the next file in the playlist when the current sound has finished playing. Another modification is the use of the local variable named sLoadURL. This variable retrieves its value from the checkField() function you created in Step 3. The value is then used in the loadSound() method of the snd_1 object.
snd_1.onSoundComplete = function():Void {
tStatus.text = "The MP3 file has finished playing."; loadFile();
this.loadFile = function(oEvent:Object):Void { var sLoadURL:String = checkField(); snd_1.loadSound(sLoadURL, true);
tStatus.text = "The MP3 file is loading."; nProgress = setInterval(checkLoad, 50, snd_1);
5. You’re ready to test the movie. Save your document and choose Control Î Test Movie (Ctrl+Enter or ^+Enter). Click the Load MP3 button and the first file in the playlist starts to play. As soon as it is finished, the second file will play, and so on.
Previous << 1 .. 269 270 271 272 273 274 < 275 > 276 277 278 279 280 281 .. 419 >> Next