AS3 中如何加载库中的声音 并控制播放 停止 代码
答案:2 悬赏:50 手机版
解决时间 2021-04-06 02:13
- 提问者网友:無理詩人
- 2021-04-05 16:56
AS3 中如何加载库中的声音 并控制播放 停止 代码
最佳答案
- 五星知识达人网友:woshuo
- 2021-04-05 18:08
1. 调用库里的声音
导入一个声音到库里面,定义链接的类名为sd
代码如下:
//调用库里声音的链接sd
var sound:sd = new sd();
var s:SoundChannel;
MC1.addEventListener (MouseEvent.MOUSE_UP,s1);
MC2.addEventListener (MouseEvent.MOUSE_DOWN,s2);
//点击播放声音
function s1 (evt:MouseEvent):void
{
s = sound.play();
}
//点击停止声音
function s2 (evt:MouseEvent):void
{
s.stop ();
//停止所有的声音
//SoundMixer.stopAll ();
}
2.加载外部声音
在文件的同一目录下放一个url.mp3的声音
代码如下:
//记录声音指针的位置
var po:Number = 0;
//加载外部声音
var url:URLRequest = new URLRequest("url.mp3");
var s:Sound = new Sound(url);
var sd:SoundChannel;
//注册侦听器
MC1.addEventListener (MouseEvent.MOUSE_DOWN,s1);
MC2.addEventListener (MouseEvent.MOUSE_DOWN,s2);
MC3.addEventListener (MouseEvent.MOUSE_DOWN,s3);
//点击播放声音
function s1 (evt:MouseEvent):void
{
sd = s.play(po);
}
//点击暂停声音
function s2 (evt:MouseEvent):void
{
po = 0;
sd.stop ();
}
//点击暂停声音
function s3 (evt:MouseEvent):void
{
po = sd.position;
sd.stop ();
}
3.连接声音
在库里面放入两个声音,连接的类名分别为s1_mp3, s2_mp3
代码如下:
//声音1
var sound1:s1_mp3 = new s1_mp3();
//声音2
var sound2:s2_mp3 = new s2_mp3();
var s1:SoundChannel;
var s2:SoundChannel;
//播放声音1
s1 = sound1.play();
//注册声音侦听器
s1.addEventListener (Event.SOUND_COMPLETE,sp);
function sp (evt:Event):void
{
//播放声音2
s2 = sound2.play();
}
导入一个声音到库里面,定义链接的类名为sd
代码如下:
//调用库里声音的链接sd
var sound:sd = new sd();
var s:SoundChannel;
MC1.addEventListener (MouseEvent.MOUSE_UP,s1);
MC2.addEventListener (MouseEvent.MOUSE_DOWN,s2);
//点击播放声音
function s1 (evt:MouseEvent):void
{
s = sound.play();
}
//点击停止声音
function s2 (evt:MouseEvent):void
{
s.stop ();
//停止所有的声音
//SoundMixer.stopAll ();
}
2.加载外部声音
在文件的同一目录下放一个url.mp3的声音
代码如下:
//记录声音指针的位置
var po:Number = 0;
//加载外部声音
var url:URLRequest = new URLRequest("url.mp3");
var s:Sound = new Sound(url);
var sd:SoundChannel;
//注册侦听器
MC1.addEventListener (MouseEvent.MOUSE_DOWN,s1);
MC2.addEventListener (MouseEvent.MOUSE_DOWN,s2);
MC3.addEventListener (MouseEvent.MOUSE_DOWN,s3);
//点击播放声音
function s1 (evt:MouseEvent):void
{
sd = s.play(po);
}
//点击暂停声音
function s2 (evt:MouseEvent):void
{
po = 0;
sd.stop ();
}
//点击暂停声音
function s3 (evt:MouseEvent):void
{
po = sd.position;
sd.stop ();
}
3.连接声音
在库里面放入两个声音,连接的类名分别为s1_mp3, s2_mp3
代码如下:
//声音1
var sound1:s1_mp3 = new s1_mp3();
//声音2
var sound2:s2_mp3 = new s2_mp3();
var s1:SoundChannel;
var s2:SoundChannel;
//播放声音1
s1 = sound1.play();
//注册声音侦听器
s1.addEventListener (Event.SOUND_COMPLETE,sp);
function sp (evt:Event):void
{
//播放声音2
s2 = sound2.play();
}
全部回答
- 1楼网友:底特律间谍
- 2021-04-05 19:44
看看帮助就知道了
我要举报
如以上问答信息为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯
正方形一边上任一点到这个正方形两条对角线的 |
阴历怎么看 ? |