Flash 如何在Actionscript 2.0中为打字机效果代码添加声音

Flash 如何在Actionscript 2.0中为打字机效果代码添加声音,flash,audio,actionscript,actionscript-2,cs4,Flash,Audio,Actionscript,Actionscript 2,Cs4,我的问题是,我想在播放打字机效果文本时实现一个按键声音(它被称为“TextBeep”,链接名称也是“TextBeep”,它是一个.WAV文件)。所有文本一出现,声音就会停止 我该怎么做?我已经找了很久了,但是ActionScript3.0只有一个,而我正在使用的代码没有。我使用的是AdobeFlashCS4 以下是我正在使用的代码: var effectTxt:String = _root.effect.text; _root.effect.text = ""; var

我的问题是,我想在播放打字机效果文本时实现一个按键声音(它被称为“TextBeep”,链接名称也是“TextBeep”,它是一个.WAV文件)。所有文本一出现,声音就会停止

我该怎么做?我已经找了很久了,但是ActionScript3.0只有一个,而我正在使用的代码没有。我使用的是AdobeFlashCS4

以下是我正在使用的代码:

    var effectTxt:String = _root.effect.text;
    _root.effect.text = "";
    var startEff:Number = 1;
    _root.onEnterFrame = function() {
        if (effectTxt.length>=startEff) {
            _root.effect.text = effectTxt.substr(0, startEff);
            startEff++;
        }
        else {
        delete _root.onEnterFrame}
    };

如果有人能告诉我如何得到它,这样它可以自动启动,只要帧开始和文本开始出现,然后停止声音后,所有的文本已经出现,这将是伟大的。另外,如果你不介意的话,你能解释一下你是如何为将来的项目做这些的吗。谢谢

所以声音效果不是一次“点击”,而是多次且长时间的,不需要一个循环,对吗? 与enterFrame相比,使用setInterval可以更好地控制键入速度

var effectTxt:String = _root.effect.text;
_root.effect.text = "";
var startEff:Number = 1;
var firstLetter:Number = 0;
mySound = new Sound();
mySound.attachSound("TextBeep");
writeText = setInterval(write, 100); // 100 means one character every 1/10 of second


function write ()  {
// launch the sound just at the first letter
firstLetter != 1 ? mySound.start() : null;
// use start(0,10) if you need to loop it ten times.
firstLetter =1;
    if (effectTxt.length>=startEff) {
        _root.effect.text = effectTxt.substr(0, startEff);
        startEff++;
    } else {
      mySound.stop();
     clearInterval(writeText);
};