PDA

View Full Version : addEventListener doesnīt work


FFighter
07-12-2005, 05:37 PM
Well, I have a nested ProgressBar component within my own component. My componentīs class extends from UIComponent. The PBar class also extends from UIComponent so it should have support for the eventDispatcher stuff right? In the draw() method Iīm trying to register a listener to the "complete" event of the ProgressBar but it just doesnīt fire the function in the object:

function draw() {

pbar = lmc.createClassObject(ProgressBar,"pbar",lmc.getNextHighestDepth());

var pbar_listener:Object = new Object();
pbar_listener.complete = function(eo:Object) {
trace("called!");
}

pbar.addEventListener("complete",pbar_listener);

}


if I just specify the callback for the complete, then it works:



pbar.complete = function() {
trace("works");
}



What could be wrong?

deadbeat
07-12-2005, 05:43 PM
Change:

var pbar_listener:Object = new Object();

to:

pbar_listener:Object = new Object();

Since you are using the var keyword, your listener is probably being deleted when the function completes, and before the callback is fired...

K.

FFighter
07-12-2005, 06:17 PM
Thanks for the reply

Iīm using SE|PY and MTASC to debug... it throws a error if I donīt use the var keyword there... anyway, I removed the declaration from the function and put in the class scope...


class mycomp extends UIComponent {
private var pbar_listener:Object;

}


it still doesnīt work :(

FFighter
07-13-2005, 01:18 AM
EDIT:

For the sake of testing, I gave up my componentīs code for a while and created an empty .fla .... The .fla has the Loader and the ProgressBar components in its library and this AS code in the first frame and nothing else:


import mx.controls.ProgressBar;
import mx.controls.Loader;

var pbarrogressBar;
var loadr:Loader;
var plbject;

pl = new Object();
pbar = _root.createClassObject(ProgressBar, "pbare",1);
loadr = _root.createClassObject(Loader,"loader",2);
loadr.contentPath = "asd.jpg";


pl.complete = function() {
trace("event fired");
}


trace(_root["pbare"]);
pbar.addEventListener("complete",pl); //desnīt work?

pbar.source = loadr;

loadr.load();


Am I missing something??

FFighter
07-14-2005, 07:41 PM
Well, found out a way trought the problem... use the "complete" event of the Loader as the ProgressBar one doesnīt seem to be emited, donīt know why though :confused: