所以我有一个 soundHandler 类,它应该播放声音,然后在声音完成播放后指向时间轴上的一个函数。但不知何故,当我尝试时,只有一种声音会播放。编辑:声音播放后,没有任何反应,即使我设置了应该做某事的 EventHandlers。这是代码:
import mx.events.EventDispatcher;
class soundHandler {
private var dispatchEvent:Function;
public var addEventListener:Function;
public var removeEventListener:Function;
var soundToPlay;
var soundpath:String;
var soundtype:String;
var prefix:String;
var mcname:String;
public function soundHandler(soundpath:String, prefix:String, soundtype:String, mcname:String) {
EventDispatcher.initialize(this);
_root.createEmptyMovieClip(mcname, 1);
this.soundpath = soundpath;
this.soundtype = soundtype;
this.prefix = prefix;
this.mcname = mcname;
}
function playSound(file, callbackfunc) {
_root.soundToPlay = new Sound(_root.mcname);
_global.soundCallbackfunc = callbackfunc;
_root.soundToPlay.onLoad = function(success:Boolean) {
if (success) {
_root.soundToPlay.start();
}
};
_root.soundToPlay.onSoundComplete = function():Void {
trace("Sound Complete: "+this.soundtype+this.prefix+this.file+".mp3");
trace(arguments.caller);
dispatchEvent({type:_global.soundCallbackfunc});
trace(this.toString());
trace(this.callbackfunction);
};
_root.soundToPlay.loadSound("../sound/"+soundpath+"/"+soundtype+prefix+file+".mp3", true);
_root.soundToPlay.stop();
}
}
这是 .fla 文件中的代码:
var playSounds:soundHandler = new soundHandler("signup", "su", "s", "mcs1");
var file = "000";
playSounds.addEventListener("sixtyseconds", this);
playSounds.addEventListener("transition", this);
function sixtyseconds() {
trace("I am being called! Sixtyseconds");
var phase = 1;
var file = random(6);
if (file == 0) {
file = 1;
}
if (file<10) {
file = "0"+file;
}
file = phase+file;
playSounds.playSound(file, "transition");
}
function transition() {
trace("this works");
}
playSounds.playSound(file, "sixtyseconds");
我完全失去了这个。已经浪费了几个小时来弄清楚。任何帮助将不胜感激。