ActionScript 3: play sound from a library with a name from a string

I am trying to write actionscript 3 code to play short sounds from a library using a dynamically generated line to load it.

In AS2, I could do something like this:

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

In AS3, however, an identifier is a class whose name seems to be already known. Is there an easy way to “attach” a sound using a string identifier in actionscript 3?

+3
source share
2 answers

, , "" "". : FogHorn

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

Source: https://habr.com/ru/post/1761572/


All Articles