0

我已经看到很多论坛试图让一种声音接踵而至

在这种情况下 LoaderS2 在 LoaderS1 之后...

有人可以帮忙吗,这是我的代码...我不知道该怎么办了...:S

这是一个显示 2 张图像的程序,用户需要在听完声音后选择正确的一张。

这个想法是在我加载 2 个图像后,我将运行 LoaderS1 将运行,HL_Left 将在图片周围制作一个矩形以突出显示图像,完成后他将复制第二个声音 LoaderS2。

这就是我想要做的......需要帮助和快速......

import flash.display.Loader;
import flash.net.URLRequest;
import flash.events.Event;

var Img_Sd:Array = new Array(5);
var Escolhas:Array = new Array(5);
var Respostas:Array = new Array(0,1,0,1,0)

var Resultado:Number = 0;
var Pos:Number = 0;

var i:Number = 0;
var b:Number = 0;

var urlE:String;
var urlD:String;
var urlS1:String;
var urlS2:String;
var urlS3:String;

var Loader_ESQ:Loader = new Loader();
var Loader_DIR:Loader = new Loader();
var Loader_S1:Sound = new Sound();
var Loader_S2:Sound = new Sound();
var Loader_S3:Sound = new Sound();

var pasta_SND:String = "Sons/";
var pasta_IMG:String = "Images/";
var num_Imag:Number = 0;
var string_aux:String;
var flag:Number = 0;


//Preenchimento do array com a informação dos ficheiros (Imagens e Sons)
for (i=0; i<=4; i++)
{

        Img_Sd[i] = [((i+1)+"E"),((i+1)+"D"),17,18,20];
}

//Event Listeners para supervisionar o estado dos botões
BT_EscolhaDIR.addEventListener(MouseEvent.CLICK, ClickDir);
BT_EscolhaESQ.addEventListener(MouseEvent.CLICK, ClickESQ);

//BT_Reeniciar.addEventListener(MouseEvent.CLICK, ClickRe);

LoadImg();
//Pos = Pos+1;

function ClickESQ(event:MouseEvent): void 
{
    Escolhas[Pos]=0;
    Pos = Pos+1;
    LoadImg();
}

function ClickDir(event:MouseEvent): void 
{

    Escolhas[Pos]=1;
    Pos=Pos+1;
    LoadImg();
}

function audioComplete(e:Event): void
{
    Loader_S2.play();
    HL_Left.visible=false;
}


function LoadImg()
{
    if (Pos<5)
    {
        urlE = pasta_IMG + Img_Sd[Pos][0] +".png";
        urlD = pasta_IMG + Img_Sd[Pos][1] +".png";

        Loader_ESQ.load(new URLRequest(urlE));
        Loader_DIR.load(new URLRequest(urlD));


        //Pos = Pos + 1;


        EscolhaESQ_MC.addChild(Loader_ESQ);
        EscolhaDIR_MC.addChild(Loader_DIR);
        HL_Left.visible=true;
        LoadSnd();

        //setTimeout(audioComplete, Loader_S1.length);
    }

    if (Pos == 5)
    {
        BT_EscolhaDIR.enabled = false;
        BT_EscolhaESQ.enabled = false;
        for (b=0;b<=4;b++)
        {
            if (Escolhas[b]==Respostas[b])
            {
                Resultado = Resultado + 1;
            }
            trace("Escolha",Escolhas[b],":Resposta",Respostas[b],"-",Resultado);
        }
        Pos=6;
    }
}

function LoadSnd()
{
    urlS1= pasta_SND + Img_Sd[Pos][2] +".mp3";
    urlS2= pasta_SND + Img_Sd[Pos][3] +".mp3";
    urlS3= pasta_SND + Img_Sd[Pos][4] +".mp3";

    Loader_S1.load(new URLRequest(urlS1));
    Loader_S2.load(new URLRequest(urlS2));
    Loader_S3.load(new URLRequest(urlS3));
    Loader_S1.play();
    Loader_S1.addEventListener(Event.SOUND_COMPLETE, audioComplete);
}
4

1 回答 1

5

该类Sound不分派Event.SOUND_COMPLETE事件。您正在寻找的是SoundChannel课程(http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/media/SoundChannel.html)。

类的play方法Sound返回一个SoundChannel实例,所以你要做的是:

var s1Channel:SoundChannel = Loader_S1.play();
s1Channel.addEventListener(Event.SOUND_COMPLETE, audioComplete);
于 2013-03-06T21:43:06.893 回答