首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >ActionScript 3-播放声音mp3时出现错误

ActionScript 3-播放声音mp3时出现错误
EN

Stack Overflow用户
提问于 2017-08-07 03:55:11
回答 1查看 74关注 0票数 0

帮帮我,我用的是Adobe Flash CS3 Professional。

代码语言:javascript
运行
复制
// i have try using this import, but still not work
/*import flash.events.Event;
  import flash.media.Sound;
  import flash.net.URLRequest;
*/

// here is the code
var req:URLRequest=new URLRequest("music.mp3");
var snd:Sound=new Sound();
snd.load(req);
var chan:SoundChannel=snd.play();// not work using 'snd.play(1);' too

chan.addEventListener(Event.SOUND_COMPLETE, onPlaybackComplete); 
function onPlaybackComplete(event:Event){
  trace("Musik Complete");
}

当我运行swf或ctrl+enter时,输出的Musik Complete没有播放任何声音,但动画仍在播放。对于动画,我只创建了简单的双胞胎运动。

我在这个目录上工作

代码语言:javascript
运行
复制
C:/flash/example.fla
C:/flash/example.swf
C:/flash/music.mp3

我也尝试过将music.mp3导入到库中。

注意:我是从我的朋友(.swf,.fla,.mp3)那里得到这个例子的。我玩的是朋友和工作分享的.swf,但当我尝试自己创作时,就不是工作了。所以,我认为music.mp3可以很好地用于闪存。下面是我的朋友代码:

代码语言:javascript
运行
复制
var Audio:musik = new musik();
var chan:SoundChannel = new SoundChannel();
// play
chan=Audio.play();
// stop
chan.stop();
// i am so confuse i run my friend project and work fine (sound and other), if i write from scrap even i write the same code, there is an error, and this the error:
// 1046: Type was not found or was not a compile-time constant: musik.
// 1180: Call to a possibly undefined method musik.
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-08-07 04:27:47

我只是在youtube上看,我漏了一步。在库中,打开music.mp3的属性并为其指定类名。

所以,我们可以使用这个var Audio:musik=new musik();调用这个类。然后,创建声音通道。至少,函数可以播放并停止使用以下内容:

代码语言:javascript
运行
复制
//play
chan=Audio.play();
// stop
chan.stop();
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/45536035

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档