Flash Animation--Control of sound techniques--playback of sound

Source: Internet
Author: User
Flash Animation | skills | control

First, the basic knowledge:
1. Start Sound Playback:
Mysoudn.start ([parameter 1: The position at which to start playing, the second],[parameter 2: The number of cycles]). Parameter 1 controls how the sound starts to play from any location.
2, two properties:
Mysoudn.position, returns the current position of the playhead, MS
Mysoudn.duration, return total sound length, MS
3, stop playing:
Mysoudn.stop ();
Notice that the playhead stops at the stop position until the next start () is moved. So you can read the position and remember to play it next time.
4. Stop from any position:
Mysoudn.stop () is not a parameter, but can continuously detect mysoudn.position, to the specified location, run Mysoudn.stop () can be parked in any location.
5, Loop Playback:
If you have a 1 anycast, and you have 4 stops at any point, you can loop through any paragraph.

Second, the production of experiments:
1. Put a progress bar clip on the stage: MCB, attach the sound to it, and use its width to display the playback progress.
2. Under MCB, place a rectangular clip: MCA, showing the total length of the progress bar.
3, build a dynamic text, instance name: Stxt, display the sound length and playback time.
4, put three buttons: Play, pause, stop. The instance name is shown below as.
5, import a sound storage, set up in the library: link--For as export--id: Sou
6, the first frame to write the following code:

var sou:sound=new Sound (MCB);//Create a sound object and associate it with a clip MCB, if you want to control multiple sounds individually, you will specify a different MC.
Sou.attachsound ("Sou");//add Sound from Library
var sout:number=0;//playback Header
Play button
Souplay.onrelease=function () {
Sou.start (sout/1000);//starting at the specified location, note that the unit is seconds
Mcb.onenterframe = function () {
sout=sou.position;//Save the Playhead position, note that the unit is milliseconds
Soudir (SouT);
}
}
Pause button
Soupause.onrelease=function () {
if (sout!=0) {
Sou.stop ();
Delete Mcb.onenterframe;
}
}
Stop button
Soustop.onrelease=function () {
sout=0;
Sou.stop ();
Soudir (SouT);
Delete Mcb.onenterframe;
}
Playback complete
Sou.onsoundcomplete = function () {
sout=0;
Soudir (SouT);
Delete Mcb.onenterframe;
}
Soudir (sou.position);
Functions for displaying sound information, passing in Parameters: current sound position
function Soudir (t): void{
Show Playback time: Current position/Total time
_root.stxt.text=t+ "/" +sou.duration;
Progress bar
_root.mcb._width=t/sou.duration*_root.mca._width;
}

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.