[Flash Basic theory Lesson 04] Make Music player [sound class]

Source: Internet
Author: User

Back to "flash Basic Theory Class-Catalog"

Train of thought: sound playback, stop, pause implementation, very simple.

Step 1:

First put three buttons, the instance name is "Start_btn" "pause_btn" "stop_btn";

Then import a sound file into the library;

When the import is complete, right-click the sound file in the Library-> Link-> Check "for ActionScript

Export and "Export in first frame", enter a name, such as "Cannon", in the identifier.

Step 2:

Join as code layer:

var mysound:Sound = new Sound();
//让mysound具有Sound类的属性和方法

mysound.attachSound("Cannon");
//mysound链接到库中名为"Cannon"的声音元件

Start_Point = 0;
//设置播放的起点位置

play_btn.onRelease = function() {
mysound.start(Start_Point/1000);};
//播放按钮:从起点位置开始播放声音,因为要接收秒数,所以要除1000

pause_btn.onRelease = function() {
Start_Point = mysound.position;
mysound.stop();};
//暂停按钮:先保存当前播放到的位置为起点,然后停止播放

stop_btn.onRelease = function() {
Start_Point = 0;
mysound.stop();};
//停止按钮:将起点位置设为0,然后停止播放

Flash Charging: Common properties and methods of sound class

(1) sound.attachsound ("Idname"): sound objects attached to sound components

mysound.attachSound("Cannon")

(2) Sound.start (playback starting point, cycle times): Start playing sound

mysound.start(5,3)
//从5秒钟位置开始播放,循环三次
mysound.start()
//从0秒钟位置开始播放,循环一次

(3) Sound.stop ("Idname"): Stop playing sound

mysound.stop()
//停止全部声音

(4) Sound.setvolume (1~100): Set volume

mysound.setVolume(50)
//设置音量为50

(5) Sound.getvolume (): Get volume Set value

mysound.setVolume(33)
trace(mysound.getVolume())
//返回33

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.