0

embedding a sound into my .swf..

[Embed(source='/audio/files/sp_worm.mp3')]
private var sf_warp_finish:Class;

the reading it here:

var sndClass:Class;
if (soundId == "sf_warp_finish") sndClass = new sf_warp_finish();

and am receiving this error:

Type Coercion failed: cannot convert GameSoundManager_sf_warp_finish@a94eb31 to Class.

Not sure why this isn't working- any ideas?

Lagoo87
  • 621
  • 1
  • 6
  • 20

2 Answers2

2

sf_warp_finish is actually the class with your embedded data; when you call new(), you instantiate it and now you have an object (not a Class object).

See http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/mx/core/SoundAsset.html for an example.

Luis
  • 1,235
  • 1
  • 12
  • 12
  • When I change it to sndClass = sf_warp_finish I can't seem to convert it to a Sound Object to play the sound? What am I missed?? – Lagoo87 Jan 17 '13 at 20:03
  • @Lagoo87 Yes, I noticed a similar problem: the mp3 I have available doesn't play. Could it be a situation like in [this other question](http://stackoverflow.com/questions/8807462/embedded-mp3-in-actionscript3-wont-play-all-the-way-through) ? Mine is 128 kbps and has an embedded image. – Luis Jan 18 '13 at 15:51
  • Ahh, that makes sense- thanks @Luis! I did not test it, but instead compiled my audio files in a .swc and accessed them via that. – Lagoo87 Jan 18 '13 at 20:03
0

It should work:

var snd:Sound;
if (soundId == "sf_warp_finish") snd = new sf_warp_finish() as Sound;
if (snd)
    snd.play();
Serge Him
  • 936
  • 6
  • 8