如何在 AS3 中播放库中的声音? [英] How to play sound from library in AS3?

查看:15
本文介绍了如何在 AS3 中播放库中的声音?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Flash 10/AS3 中,我添加了一些声音,它似乎工作正常,但我认为我做错了.我将声音导入到库中,但我相信它是从带有 swf/sound 的文件夹中重新加载它的.我正在加载它们:

In Flash 10/AS3, I added some sound and it seems to be working alright, but I think I'm doing it wrong. I imported the sound into the library, but I believe that it's reloading it from the folder with the swf/sound. I'm loading them like so:

var request1:URLRequest = new URLRequest("CLICK8C.mp3");
clickSound = new Sound();
clickSound.addEventListener(Event.COMPLETE, completeHandler);
clickSound.load(request1);

有没有办法让它从库中加载它?

Is there a way to get it to just load it from the library?

推荐答案

您需要使库中的声音可用​​于 actionscript.之后,您可以像实现任何其他类一样实现声音对象.

You need to make the sound in the library available to actionscript. After that, you can implement the sound object like any other class.

要使库对象可用于 actionscript,请左键单击库中的项目并选择链接".选中为 ActionScript 导出"旁边的框.然后您需要为该对象提供一个类名,并且由于您正在处理一个声音,请确保基类是一个 Sound 对象.

To make a library object available for actionscript, left click the item in the library and select 'Linkage'. Check the box next to 'Export for ActionScript'. You'll need to then give the object a class name and since you are dealing with a sound, make sure the base class is a Sound object.

假设您将声音类命名为MySound",您现在可以通过这样的动作脚本访问该对象(结合问题中的代码):

Let's say you named your sound class "MySound", you can now access this object via actionscript like this (incorporating your code from the question):

var mysound:MySound = new MySound(); 
mysound.addEventListener(Event.COMPLETE, completeHandler); 
mysound.play();

注意:如果您想进一步控制声音(停止、重新播放等),您需要创建一个 SoundChannel 对象.(请参阅下面的文档)

note: if you want to further control the sound (stop, rew, etc), you'll need to create a SoundChannel object. (see documentation below)

Adobe 声音对象文档

这篇关于如何在 AS3 中播放库中的声音?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆