动作3:播放声音从库中与字符串名称 [英] Actionscript 3: playing sound from library with name from string

查看:132
本文介绍了动作3:播放声音从库中与字符串名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试写一些动作3 code,从库中播放短的声音,使用动态创建的字符串来加载它。

I am trying to write some actionscript 3 code to play short sounds from the library, using a dynamically created string to load it.

在AS2,我可以做这样的事情:

In AS2, I could do something like this:

mySound = new Sound();
mySound.attachSound("any concatenated string" + foo);

在AS3然而,所述标识符是类名,看来,必须已经公知的。有一个简单的方法来连接使用标识为一个字符串在ActionScript 3的声音?

In AS3 however, the identifier is a class whose name, it seems, must be already known. Is there a simple way to 'attach' a sound using the identifier as a string in actionscript 3?

推荐答案

首先,在资料库中,设置了声音文件之类的联动右击,选择属性和编辑在连接段类领域。在这个例子中这将是类别:雾角

First, in your library, set the class linkage of a sound file by right clicking, selecting properties and editing the Class field in the Linkage section. In this example it will be Class:FogHorn

 import flash.utils.getDefinitionByName;    
 var SoundClass:Class = getDefinitionByName("FogHorn") as Class;
 var newSound:Sound = new SoundClass(); 
 newSound.play()

这篇关于动作3:播放声音从库中与字符串名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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