正在开发一个处理ActionScript for Starling项目中的声音文件的类。我希望您对实施的看法以及它是否表现良好。 (嵌入文件会使这个文件变得越来越大)。
这是另一回事,如果是嵌入式的,这是件坏事吗?我的意思是,如果我嵌入了这么多语音文件,即使它们不会被使用会影响性能吗?
无论如何,这是我的实施:
package assets
{
import flash.media.Sound;
import flash.media.SoundChannel;
import flash.media.SoundTransform;
import flash.utils.Dictionary;
/**
* ...
* @author Shaun Stone
*/
public class CharacterDialogueSoundAssets
{
// This will return the voice file is exists
private static var _soundAssetsDictionary:Dictionary= new Dictionary();
[Embed(source = "../../../media/sounds/dialogue/voice_file_1.mp3")]
public static const VOICE_FILE_1:Class;
/**
* Get voice file from dictionary
*
* @param name
* @return
*/
public static function getVoiceFile(name:String):Sound
{
if (_soundAssetsDictionary[name] == undefined)
{
var voiceFile:Sound = new CharacterDialogueSoundAssets.name() as Sound;
_soundAssetsDictionary[name] = voiceFile;
}
return _soundAssetsDictionary[name];
}
public static function disposeOfVoiceFile(name:String):void
{
if (_soundAssetsDictionary[name] == undefined)
{
return;
}
//dispose for garbage collection
_soundAssetsDictionary[name] = undefined;
}
}
}