ActionScript 2: Event doesn't fire?

Posted by Pascal Schuster on Stack Overflow See other posts from Stack Overflow or by Pascal Schuster
Published on 2012-07-02T03:33:38Z Indexed on 2012/07/03 3:15 UTC
Read the original article Hit count: 172

Filed under:
|

So I have a soundHandler class that's supposed to play sounds and then point back to a function on the timeline when the sound has completed playing. But somehow, only one of the sounds plays when I try it out. EDIT: After that sound plays, nothing happens, even though I have EventHandlers set up that are supposed to do something. Here's the code:

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();
}
}

Here's the code from the .fla file:

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");

I'm at a total loss for this one. Have been wasting hours to figure it out already. Any help will be deeply appreciated.

© Stack Overflow or respective owner

Related posts about actionscript-2

Related posts about sounds