Flash Player can only play 32 sounds at a time

  • strict warning: Non-static method view::load() should not be called statically in /home/curiousm/public_html/blog.curiousmedia.com/sites/all/modules/views/views.module on line 843.
  • strict warning: Declaration of views_plugin_display::options_validate() should be compatible with views_plugin::options_validate(&$form, &$form_state) in /home/curiousm/public_html/blog.curiousmedia.com/sites/all/modules/views/plugins/views_plugin_display.inc on line 1877.
  • strict warning: Declaration of views_plugin_display_page::options_submit() should be compatible with views_plugin_display::options_submit(&$form, &$form_state) in /home/curiousm/public_html/blog.curiousmedia.com/sites/all/modules/views/plugins/views_plugin_display_page.inc on line 481.
  • strict warning: Declaration of views_plugin_display_block::options_submit() should be compatible with views_plugin_display::options_submit(&$form, &$form_state) in /home/curiousm/public_html/blog.curiousmedia.com/sites/all/modules/views/plugins/views_plugin_display_block.inc on line 193.
  • strict warning: Declaration of views_handler_field_broken::ui_name() should be compatible with views_handler::ui_name($short = false) in /home/curiousm/public_html/blog.curiousmedia.com/sites/all/modules/views/handlers/views_handler_field.inc on line 641.
  • strict warning: Declaration of views_handler_sort_broken::ui_name() should be compatible with views_handler::ui_name($short = false) in /home/curiousm/public_html/blog.curiousmedia.com/sites/all/modules/views/handlers/views_handler_sort.inc on line 82.
  • strict warning: Declaration of views_plugin_row::options_validate() should be compatible with views_plugin::options_validate(&$form, &$form_state) in /home/curiousm/public_html/blog.curiousmedia.com/sites/all/modules/views/plugins/views_plugin_row.inc on line 135.
  • strict warning: Declaration of views_plugin_row::options_submit() should be compatible with views_plugin::options_submit(&$form, &$form_state) in /home/curiousm/public_html/blog.curiousmedia.com/sites/all/modules/views/plugins/views_plugin_row.inc on line 135.

In as3 you play a sound by creating a Sound object, and calling its play() method. play() returns a SoundChannel object which has a soundTransform property that you can use to adjust the volume and panning of the playing sound.
If you like, you can think of the Sound class as being the data, and the SoundChannel class as the actual playing sound.

A potentially important detail you may not be aware of (it is not mentioned in the API reference) is that Flash Player will only allow a maximum of 32 sound channels to play simultaneously. If you already have 32 active SoundChannels, and you try to call the play() method of a sound, it will return null, and the sound will not play. That's not 32 channels per swf btw, that's 32 channels per player. So if whoever is viewing your swf has other swfs open at the same time (in another tab, or another window) those other swfs could very well monopolize all 32 channels, leaving you with no ability to play sound.

Therefore, when attempting to play a sound it is important that you check to make sure you actually got access to a SoundChannel before you attempt any soundTransform operations.
If you do this:

var st:SoundChannel = mySound.play();
st.soundTransform = new SoundTransform(0.5);

there's a chance that mySound.play() will return null, and your movie will generate a runtime error.

Instead, you should do this:

var st:SoundChannel = mySound.play();
if(st)
{
    st.soundTransform = new SoundTransform(0.5);
}
else
{
    //take alternate action if necessary
}

That way if mySound.play() does return null, your movie doesn't break.

Tags: Flash, sound

Comments

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <pre> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.

More information about formatting options