PDA

View Full Version : Cannot set up an addEventListener in a custom component


PowerfulWebsites
09-02-2006, 04:58 AM
I'm trying to set up an addEventListener to a sound object inside a method in a custom component.

I am able to set it up with a simple callback, but I need to be able to generate an eventObject.

This works: (I'm generating my sound object name dynamically)


// This works but does not dispatch an eventObject
this[var_tempSoundObjName] = new Sound(this);
this[var_tempSoundObjName].attachSound(this.pSoundReference);
this[var_tempSoundObjName].start();

this[var_tempSoundObjName].onSoundComplete = Delegate.create(this, onSoundFinished);


This does not work (nor do any other of the many combinations I have tried):

var sound = new Sound(this);
sound.attachSound(this.pSoundReference);
sound.start();

var myListener = new Object();
myListener.onSoundComplete = function(evt:Object):Void{
trace("end of sound");
}
sound.addEventListener("onSoundComplete", myListener);


All I'm trying to do is set up a onSoundComplete callback that passes an eventObject to a function.

Any help is greatly appreciated.

PowerfulWebsites
09-02-2006, 05:29 AM
First off . . . sorry about not posting this in the right place originally.

With some more sniffing around (not in the macromedia docs, by the way) I managed to get it working, but not the way that I'd like.

This works:


var sound = new Sound(this);
sound.attachSound(this.pSoundReference);
sound.start();

var listenerObj = new Object;
sound.onSoundComplete = function (eventSrc:Object){
trace("event object");
}
listenerObj = addEventListener ("onSoundComplete", listenerObj );



However, I'd like to set it up to point to another method in my component, not one in-line. And I'd like to use the Delegate.create feature so that the method that is called is run in the objects namespace.

Any help is greatly appreciated.