Flash Hacks. 100 Industrial-Strength Tips & Tools Free Open Book

Flash Hacks. 100 Industrial-Strength Tips & Tools

Previous Section  < Day Day Up >  Next Section

Hack 54 The Ubiquitous Sound-Kicker Hack

figs/moderate.gif figs/hack54.gif

Fix the Flash timeline sound-sync bug.

There is a problem in Flash with regard to the way it synchronizes sound to keyframes—you can't do it.

If you use event sounds (that is, a sound that must be fully loaded before it can be played, typically reserved for short sounds that are held in memory if needed again), they will start at the keyframe you attach them to, but the frame they end at is anyone's guess. If, for example, you start a 1-second sound on a 12-fps timeline, there is almost no chance that the sound will end exactly 12 frames later.

This "feature" causes real problems if you want to create a continuous sound consisting of a sequence of sounds attached to keyframes. If the exact frame when a sound will end is variable, you have no way of knowing when to start the next sound. For example, suppose you had two sound files, song01.wav and song02.wav, that create a continuous piece of music when played one after the other.

To mesh seamlessly, your sounds' durations must be exact multiples of the frame rate. If they are not, you can change the sound duration [Hack #57] in a sound-processing application such as Sony's Acid, Adobe Audition, or Audacity. To make sounds mesh seamlessly, you must overcome the sound-sync bug, as well as make your sounds exact multiples of the frame rate.

If you attach the two sound files to your timeline so that when one stops the other starts, as shown in Figure 7-6, you might expect there to be a seamless transition between the sounds in Flash, but there isn't, because of the aforementioned bug.

Figure 7-6. Attaching two sounds on the timeline doesn't guarantee that the second one starts when expected
figs/flhk_0706.gif


Although the sound to the left finishes just before the one to the right starts, there will be a pause between the two because there is no real synchronization.

Flash guarantees synchronization only when using stream sounds (i.e., sounds that begin playing even before being downloaded in their entirety). But in some situations, stream sounds have disadvantages compared to event sounds. In particular, you have to reload a stream sound every time you want it to play, whereas event sounds stay in memory.

This hack gives you the synchronization you need by fooling the Flash Player into thinking that the timeline contains stream sounds when it actually contains event sounds.

To add a stream sound to fool Flash into synchronizing all sounds, create a keyframe in frame 5 of your timeline and attach a sound, as shown in Figure 7-7.

Figure 7-7. Attaching a stream sound to the timeline to force synchronization
figs/flhk_0707.gif


Then Delete all frames in the same layer after frame 5. With the keyframe still selected, make this sound a stream sound using the Sync drop-down list in the Properties panel.

Finally, click the Edit button on the Properties panel, and use the Volume Envelope control points, as shown in Figure 7-8, to set the volume of your stream sound to zero.

Figure 7-8. Volume Envelope control for a sound
figs/flhk_0708.gif


This gives you a stream sound of duration 1 frame and zero volume. This sound "kicks" the Flash Player sound engine into treating the entire timeline as if it contains stream sounds, forcing it to sync all sounds (including event sounds) to the timeline. Testing will show that your previously unsynchronized event sounds play nearly seamlessly, allowing smoother and more reliable sound transitions.

Final Thoughts

Not being able to sync event sounds has put a lot of designers off trying anything complicated with Flash sound, especially in the pre-Flash MX days before Sound.onSoundComplete( ).

Creating a SWF containing kicker-synched sounds and loading it into a level using loadMovieNum( ) is an easy way to create a downloaded sound track that contains the reusability of event sounds with the streaming ability of stream sounds. For more sound synchronization capabilities, use cue points [Hack #59] .

    Previous Section  < Day Day Up >  Next Section
    Index: [SYMBOL][A][B][C][D][E][F][G][H][I][J][L][M][N][O][P][Q][R][S][T][U][V][W][X][Z]


         Main Menu
    Flash Hacks
    Table of Contents
    Copyright
    Credits
    Foreword
    Preface
    Chapter 1. Visual Effects
    Chapter 2. Color Effects
    Chapter 3. Drawing and Masking
    Chapter 4. Animation
    Chapter 5. 3D and Physics
    Chapter 6. Text
    Chapter 7. Sound
    Hacks #52-60
    Hack 52 Create a Flash Speech Synthesizer
    Hack 53 A Talking, Lip-Synched Avatar
    Hack 54 The Ubiquitous Sound-Kicker Hack
    Hack 55 Turn Low-Bandwidth Monaural Sounds into Stereo Sounds
    Hack 56 Real-Time Sound Effects
    Hack 57 Quickly Create UI Sounds
    Hack 58 Optimize Sound
    Hack 59 Sound Time Codes (Cue Points)
    Hack 60 A Custom Sound Transform Class
    Chapter 8. User Interface Elements
    Chapter 9. Performance and Optimization
    Chapter 10. ActionScript
    Chapter 11. Browser Integration
    Chapter 12. Security
    Colophon
    Index


    More Books
    PHP Hacks
    Processing Xml With Java - A Guide To Sax, Dom, Jdom, Jaxp, And Trax
    The Koran (Holy Qur'an)
    Macromedia Flash 8 Bible
    Search Engine Optimization for Dummies
    YouTube Traffic
    PHP 5 for Dummies
    Harry Potter and The Chamber of Secrets
    Harry Potter and the Sorcerer's Stone
    The Pilgrim's Progress
    Wireless Hacks
    Flash Hacks. 100 Industrial-Strength Tips & Tools
    PayPal Hacks. 100 Industrial-Strength Tips and Tools
    Amazon Hacks
    Pdf Hacks
    The Da Vinci Code
    Google Hacks
    The Holy Bible
    Windows XP For Dummies
    Harry Potter and the Half-Blood Prince
    Seo Book
    Upgrading and Repairing Networks
    Macromedia Dreamweaver 8 UNLEASHED
    Windows XP Annoyances
    Windows XP Hacks
    Microsoft Windows XP Power Toolkit
    Teach Yourself MS Office In 24Hours
    iPod & iTunes Missing Manual
    PC Hacks 100 Industrial-Strength Tips and Tools
    PC Overclocking, Optimization, and Tuning - 2th Edition
    PC Hardware In A Nutshell 3rd Edition
    PC Hardware in a Nutshell, 2nd Edition
    Upgrading and Repairing PCs
    Google for Dummies
    MySQL Cookbook
    Teach Yourself Macromedia Flash 8 In 24 Hours
    PHP CookBook
    Sams Teach Yourself JavaScript in 24 Hours
    PHP5 Manual
    Free Games Paper Airplanes
    500 Juegos Gratis 500 Giochi Gratis 500 Jeux Gratuits 500 Jogos Gratis 500 Kostenlose Spiele