load sound dynamically in as2 having problem

旧时模样 提交于 2019-12-13 04:33:46

问题


I want to load sound placed in sounds folder. Code is

var my_sound = new Sound();
my_sound.loadSound("sounds/sound1.mp3");

my_sound.onLoad = function(success:boolean){

     if(success){
        my_sound.start();
      }
}

This plays sound when flash is open and pressing CTRL+ENTER(Test Movie).

but when we plays the swf it won't play sound.

for this problem i found one solution.

i made off onLoad function. and the Test Movie. Now the opposite things happend.

It dosen't play when press CTRL+ENTER (TestMovie);

but it plays when swf is playing.

Is there any other way of loading sound.


回答1:


Try:

var my_sound:Sound = new Sound();
my_sound.onLoad = function(success:Boolean)
{
    if (success)
    {
        my_sound.stop();
    } 
};
my_sound.loadSound("sounds/sound1.mp3", true);

This will stop the sound as soon as it's loaded. Whenever you want to start the sound, just call this function:

my_sound.start();


来源:https://stackoverflow.com/questions/593928/load-sound-dynamically-in-as2-having-problem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!