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

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

问题描述

在Flash 10 / AS3,我加了一些声音,似乎是工作好了,但我觉得我做错了。我输入的声音进库,但我相信这是从与SWF /声音文件夹重装吧。我加载它们像这样:

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?

推荐答案

您需要在库中的声音提供给动作。在这之后,你可以实现像任何其他类的声音对象。

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导出。你需要然后给该对象的类名和因为你正在处理一个声音,确保基类是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,你现在可以通过动作像这样访问这个对象(从合并的问题,您的code):

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天全站免登陆