A small problem and solution for Flash built-in class sound

Source: Internet
Author: User
Solve | problem: Two voices cannot be controlled independently
var _tmp;
var s1_sound = new sound ();
var s2_sound = new sound ();
S1_sound.attachsound ("S1");
S2_sound.attachsound ("S2");
S1_sound.start (0,1000);
_btn.onpress = function () {
_tmp =!_tmp;
if (_tmp) {
S2_sound.start ();
} else {
S2_sound.stop ();
}
This code wants the sound in the library to S1 as a background music, while S2 is controlled by the button _btn (click play/click to stop).
--but it backfired. Here's a s2_sound.stop () not only the s2_sound stopped, but also the S1_sound also stopped.
Workaround: The sound is loaded by an external. mp3 file.
var _tmp;
var s1_sound = new sound ();
var s2_sound = new sound ();
S1_sound.onload = function () {
This.start ();
}
S1_sound.loadsound ("S1.mp3");
S2_sound.loadsound ("S2.mp3");
_btn.onpress = function () {
_tmp =!_tmp;
if (_tmp) {
S2_sound.start ();
} else {
S2_sound.stop ();
}
The control section (_BTN) code has not changed and the problem has been resolved.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.