Get sound length in actionscript
I think my question is really basic. I am trying to use the class Sound of actionscript. My code is really basic :
var snd:Sound = new Sound();
snd.load(n开发者_C百科ew URLRequest("mysound.mp3"));
trace( new String(snd.length));
snd.play();
The audio is playing very well but in my trace, I get 0 instead of the length in milliseconds of the Sound. Any idea ?
This is as it is intended to work.
snd.load()
loads asynchronously. This means that the code will NOT freeze while the sound is loading.
This was especially designed keeping in mind the use of Flash in Rich Internet Applications where large sound files might be loaded. In such cases, it would make for horrible user experience if the application was to hang while the sound loaded.
Immediately after the load call, nothing has been loaded, hence snd.length
returns 0. The onSoundComplete
event is fired when the sound has loaded completely, which is when you get the expected value for snd.length
.
Cheers,
精彩评论