Flash as3.0笔记 Sound类的使用

来源:互联网 发布:读屏软件安卓版 编辑:程序博客网 时间:2024/06/05 05:04
    Sound 类允许您在应用程序中使用声音。 使用 Sound 类可以创建新的 Sound 对象、将外部 MP3 文件加载到该对象并播放该文件、关闭声音流,以及访问有关声音的数据,如有关流中字节数和 ID3 元数据的信息。 可通过以下项对声音执行更精细的控制:声音源(声音的 SoundChannel 或 Microphone 对象)和 SoundTransform 类中用于控制向计算机扬声器输出声音的属性。     Sound () 构造函数 创建一个新的 Sound 对象。 如果将有效的 URLRequest 对象传递到 Sound 构造函数,该构造函数将自动调用 Sound 对象的 load() 函数。 如果未将有效的 URLRequest 对象传递到 Sound 构造函数,则必须自己调用 Sound 对象的 load() 函数,否则将不加载流。 一旦对某个 Sound 对象调用了 load(),就不能再将另一个声音文件加载到该 Sound 对象中。 若要加载另一个声音文件,请创建新的 Sound 对象。

length 属性
length:Number [read-only]
语言版本 : ActionScript 3.0
Player 版本 : Flash Player 9
当前声音的长度(以毫秒为单位)。
实现
public function get length():Number

url 属性
url:String [read-only]
从中加载此声音的 URL。 此属性只适用于使用 Sound.load() 方法加载的 Sound 对象。 对于与 SWF 库的声音资源关联的 Sound 对象,url 属性的值为 null。 首次调用 Sound.load() 时,url 属性最初具有 null 值,因为最终 URL 未知。 只要从 Sound 对象中调度了 open 事件,url 属性就会具有非空值。
实现
public function get url():String

var snd:Sound = new Sound(new URLRequest("repeatingSound.mp3"));snd.play(1000, 3);

在此示例中,从声音开始后的 1 秒起连续播放声音三次。

实例

import flash.media.SoundChannel;var pos; //声音停止的位置var bgsound: bg_sound = new bg_sound(); //加载进声音var channel: SoundChannel = new SoundChannel();  //声道channel = bgsound.play();  //把声音的控制交给声道btn.addEventListener(MouseEvent.CLICK, fn)function fn(e){     pos =  channel.position;//注意保存位置必须要在声道停止之前,否则会错误     channel.stop();//注意声音本身是无法stop的,就是不能bg_sound.stop() }btn2.addEventListener(MouseEvent.CLICK, fn2)function fn2(e){     channel = bgsound.play(pos);}//音量的控制var vlCont:SoundTransform = new SoundTransform();vlCont.volume = 0.1;  //声音的大小,0-1channel.soundTransform = vlCont;//声音加载完成后调用的事件channel.addEventListener(Event.SOUND_COMPLETE, f_complete);function f_complete(e){     trace("adasd");     trace(e);}
0 0
原创粉丝点击