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