Flash Sound Control detailed

Source: Internet
Author: User
Control | detailed

Sound is an important component of multimedia, the proper and flexible use of sound is often the key to the success or failure of multimedia works. Flash as a popular multimedia tool, the use of its voice is also rich and diverse, this article explores the use of sound in flash several situations, hope to be helpful to everyone.

the use of sound in the timeline

This is the most commonly used voice in Flash, any flash textbook will talk about this problem, so just make a simple explanation.

After you set up a keyframe, you can make the sound settings for that frame in the Frame property panel as soon as you import the sound file. The synchronization properties (sync) of sound are mainly as follows:

1. Events (event). The sound set in this way will play independently of the timeline, and as long as you don't stop in any other way, it will play until the end, and the biggest benefit is that it can be used to set some sort of loop-like playback effect, as long as you set the Loop property (loop) behind it enough.

2. Start (start). The feature is that when the frame starts playing, the sound from the previous frame call in the animation is stopped, and only the sound in the current frame is played.

3. Stops (stop). When set, the sound of the current frame will stop playing immediately.

4. Data flow (stream). When set, the playback of a move is synchronized with the sound, and if the animation download speed does not keep up with the sound, the associated frame is skipped and the sound is synchronized. Also, if the (stop) animation stops in play, the sound will stop, but if you use the plays () statement, the sound will play again from the stop.

calling sounds with ActionScript statements

Flash provides powerful script editing capabilities, almost comparable to a number of specialized programming languages, is more multimedia than a chip, the use of Flash scripting language to invoke sound, whether the effect or flexibility, are worth a try.

1. Add sound

Import external sound, press ctrl+l key, pop-up library window, select the imported sound, right-click, select the Link menu item in the pop-up menu, pop the Link Properties dialog box, select the Export for Action script check box, and then the "identifiers" column in the upper part of the dialog box becomes available, in which you enter its identity name, Here we assume that the input is "SD", and that this identity will be used as a flag for that sound in the program, so multiple sounds must not use the same identifier.

Enter the following statement on the first frame of the Flash timeline:

Mysong = new Sound ()

Mysong.attachsound ("SD")

The above statement defines a sound event mysong, and then uses the Mysound.attachsound ("SD") statement to attach the sound in the library to this sound event.

2. Playback and stop of sound

Add the "Mysong.start ()" Statement to the frame you want to play to let the sound sheet play.

When you need to stop, you can add the Mysong.stop () statement.

3. Calling external sound files

Flash can dynamically load external MP3 files while playing, which provides greater flexibility for multimedia design and reduces the disk space occupied by the work. The implementation method is as follows (assuming that there are music.mp3 files in the same directory):

Mysong=new Sound ()

Mysong.loadsound ("Music.mp3", false)

Description: The first line of the statement establishes a sound event or sound stream, and the second row Music.mp3 loaded onto the sound event sounds stream, the false in the Loadsound () statement is an optional number, and False indicates that Mysound is a sound event, True to indicate that Mysound is a stream of sound, it is recommended that sound events be used for ease of control, and if you are using a sound stream, the sound will no longer play with Mysond.start () after it has stopped.

third, sound cycle playback

As mentioned earlier, when you set a key frame's sound synchronization property on the timeline as event, enter a large enough number of loops to make sounds similar to the effect of looping, but this cycle is only similar, one number of times, there are always playback completed time, when the two stopped, it is difficult to play again. Below, to introduce a real loop with code, and, also can be a button to achieve sound playback also stop switching, want to broadcast on the broadcast, want to stop, not fast.

We can add the following code to the first frame in the timeline:

Mysong = new Sound ()

Mysong.attachsound ("SD")

Mysong.onsoundcomplete = function () {

Mysong.start ()}

The third line of the code above is the key to implementing the loop, which creates the function that is executed when the Onsoundcomplete event is invoked, Onsoundcomplete the event that is automatically invoked when the sound is played, so that when the sound is finished, the Mysong.start () is automatically executed Keep the sound playing. If the sound is stopped by the code when it plays (Mysong.stop ()), the sound is not repeated.

Adding the above code to the action of a button and slightly changing it becomes a toggle button that controls the playback and stopping of the sound.

First in the timeline after the first frame of the code plus:

Mysong.play ()///Make sound play at the beginning of the animation

var Soundkey=1//define variable Soundkey, monitor sound playback

Then insert a new layer on the timeline, put a button on the top, select the button, press the shortcut key "F9", pull up the Action editing window, enter the following code:

On (release) {

Soundkey=-soundkey//Make the variable value the opposite number of the original value

if (soundkey==1) {

Mysong.stop ()

Mysong.start ()

//If the Soundkey value is positive, play the Sound, Mysong.stop () to stop the sound after the broadcast, so as to avoid overlapping sound, affect the effect

if (soundkey==-1) {

Mysong.stop ()

///If the Soundkey value is negative, the sound stops

}



Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.