使用Effect标签实现事件声音效果

      FLEX 2005-7-27 16:40
Flex中的按钮音效使用方法和FLASH中不一样了,
如何给按钮添加声音效果要用到Effect标签,具体做法如下:
新建一个as文件ButtonSound.as

class ButtonSound extends mx.effects.Effect
{
[Embed(mimeType="audio/mpeg",source="Button.mp3")]
//注意不要使用wav格式的声音
var soundSymbol:String;
var s:Sound;
public function playEffect():Void
{
super.playEffect();
s = new Sound();
s.attachSound(soundSymbol);
s.start();
}
public function endEffect():Void
{
s.stop();
}
}

ButtonSound.as同级目录下新建一个MXML文件,代码如下:

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.macromedia.com/2003/mxml" xmlns:local="*"
pageTitle="ButtonSound" >

<!-- 声明音效 -->
<mx:Effect>
<local:ButtonSound name="ButtonSoundEffect"/>
</mx:Effect>

<mx:Button label="RIACN" click="getURL('http://www.riacn.com','_blank');" mouseDownEffect="ButtonSoundEffect"/>

</mx:Application>

另外mxml文件的命名要注意,不要用sound作为mxml的名字,否则Flex会认为文件名和内置的Sound对象冲突。

标签集:TAGS:
回复Comments() 点击Count()

回复Comments

{commentauthor}
{commentauthor}
{commenttime}
{commentnum}
{commentcontent}
作者:
{commentrecontent}

注册5D通行证,立刻拥有自己的博客发表留言

用户:  密码: 匿名
内容:
加粗 下划线 文本颜色 居中 插入链接 建立Google搜索链接 插入图片 引用文本
 
汗 喜欢 骄傲的笑 哭 酷! 愤怒 黑线 什么? 猥琐 偷笑 无语 晕 吃惊 诱惑
smile frown redface biggrin wink rolleyes mad eek 禁止笑脸转换
zoom inzoom out
验证: checkcode 换一个