Flash 闪光播放/暂停声音切换按钮
我一直在谷歌上搜索,但没有找到where或过时的教程。有人知道如何使用Flash上的ActionScript 3按钮切换音频吗?您需要使用SoundTransform(Flash.media)和SoundChannel(Flash.media)Flash 闪光播放/暂停声音切换按钮,flash,actionscript-3,Flash,Actionscript 3,我一直在谷歌上搜索,但没有找到where或过时的教程。有人知道如何使用Flash上的ActionScript 3按钮切换音频吗?您需要使用SoundTransform(Flash.media)和SoundChannel(Flash.media) 这将使用SoundChannel的soundTransform属性,该属性允许您控制音量。请记住,您必须保留mySound和mySC,而myST将只是在函数中创建的变量。您需要使用SoundTransform(flash.media)和SoundChan
这将使用SoundChannel的soundTransform属性,该属性允许您控制音量。请记住,您必须保留mySound和mySC,而myST将只是在函数中创建的变量。您需要使用SoundTransform(flash.media)和SoundChannel(flash.media)
这将使用SoundChannel的soundTransform属性,该属性允许您控制音量。请记住,您必须保留mySound和mySC,而myST只是在函数中创建的一个变量。要切换播放/暂停,您需要记录用户暂停音频的位置 要像在屏幕截图中一样使用库中的声音,需要将该声音文件提供给Actionscript 首先,右键单击库中的声音文件,然后单击属性…。在属性窗口中,选中导出Actionscript的
框。将类名更改为您自己的名称,如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
}
}
现在,在代码内部,您将使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
}
}
使用外部文件
您需要使用URLRequest类来指向mp3文件所在的位置。如果该文件与您发布的swf文件位于同一目录中,则看起来是这样的
var mySound:Sound = new Sound(new URLRequest("whatever.mp3"));
要切换播放/暂停,您需要记录用户暂停音频的位置
要像在屏幕截图中一样使用库中的声音,需要将该声音文件提供给Actionscript
首先,右键单击库中的声音文件,然后单击属性…
。在属性窗口中,选中导出Actionscript的框。将类名更改为您自己的名称,如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
}
}
现在,在代码内部,您将使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
}
}
使用外部文件
您需要使用URLRequest类来指向mp3文件所在的位置。如果该文件与您发布的swf文件位于同一目录中,则看起来是这样的
var mySound:Sound = new Sound(new URLRequest("whatever.mp3"));
new Sound()构造函数中的“request”必须是指向要播放的mp3文件的URL请求。“我应该说清楚的。”丹,看我上面编辑的答案。我将其更改为使用库中的声音。new sound()构造函数中的“request”必须是指向要播放的mp3文件的URL请求。“我应该说清楚的。”丹,看我上面编辑的答案。我把它改成使用图书馆的声音。