Flash播放/暂停声音切换按钮

tes*_*est 0 flash actionscript-3

我用谷歌搜索和谷歌搜索,但没有得到任何地方或过时的教程.任何人都知道如何制作它,以便我可以使用Flash上​​的ActionScript 3使用按钮切换音频?

knu*_*uck 5

要切换播放/暂停,您需要记录用户暂停音频的位置.

要像在屏幕截图中一样使用库中的声音,您需要将该声音文件提供给您的Actionscript.

首先,右键单击库中的声音文件,然后单击Properties....在"属性"窗口中,选中复选框Export for Actionscript.将类名更改为您自己的名称,例如MySong.

现在在代码中而不是指向外部Sound文件,您将创建mySound一个实例MySong.

var isPlaying:Boolean;
var pausePosition:Number;
var myChannel:SoundChannel = new SoundChannel();
// edited mySound to use an internal sound file with Class of MySong
var mySound:Sound = new MySong();
var myButton:MovieClip;

myButton.addEventListener(MouseEvent.CLICK, playPauseClicked);

myChannel = mySound.play();
isPlaying = true;

function playPauseClicked(e:MouseEvent):void
{
    if (isPlaying) {
        pausePosition = myChannel.position;
        myChannel.stop();
        isPlaying = false;
        // change the display of your button to show the pause state
    } else {
        myChannel = mySound.play(pausePosition);
        isPlaying = true;
        // change the display of your button to show the playing state
    }
}
Run Code Online (Sandbox Code Playgroud)

使用外部文件

您需要使用URLRequest类指向mp3文件所在的位置.如果文件与发布的swf文件位于同一目录中,则它看起来像这样.

var mySound:Sound = new Sound(new URLRequest("whatever.mp3"));
Run Code Online (Sandbox Code Playgroud)