PDA

View Full Version : Problems with addEventListener


smwoody88
03-08-2007, 12:11 AM
I am trying to add an event listener to a combobox (or any component) that is contained within a movieclip that is loaded into an accordion component using an actionscript file. None of the events are being called! It is a very strange problem and I can't seem to figure it out. I am able to add a combobox dynamically and then add an event listener and it works perfectly.
I need to layout a fairly extensive interface and I don't want to have to lay out each component using actionscript.

I have attached the test .fla and .as file to illustrate the problem.

If you don't want to download the files I have copied the code from my actionscript file:

import mx.containers.Accordion;
import mx.controls.ComboBox;
import mx.core.View;
class Test {
function Test(){
var test_acc:Accordion = _root.createClassObject(Accordion, "options_acc", _root.getNextHighestDepth());
test_acc._lockroot = true;
var test1_mc = test_acc.createChild("_mc", "test1_mc", {label:"Test 1"});
var test2_mc = test_acc.createChild("_mc", "test2_mc", {label:"Test 2"});

var dynamic_cb = test1_mc.createClassObject(ComboBox, "testing", test1_mc.getNextHighestDepth());
dynamic_cb.dataProvider = [{label:"Dynamic 1", data:"test1"}, {label:"Dynamic 2", data:"test2"}, {label:"Dynamic 3", data:"test3"}];
dynamic_cb.move(150, 40);

var cbListener:Object = new Object();
cbListener.change = function(evt_obj:Object) {
trace("In change listener");
}

test1_mc.static_cb.addEventListener("change", cbListener);
test2_mc.static_cb.addEventListener("change", this);

dynamic_cb.addEventListener("change", cbListener);
dynamic_cb.addEventListener("change", this);

test1_mc._btn.onPress = function(){
trace(test1_mc.static_cb.selectedItem.label);
}

}
function change(evt){
trace("In change function");
}
}


Thanks for any help!!

astgtciv
03-13-2007, 05:58 AM
Try adding a function as a listener instead of an object, like


var onChangeFunc:Function = function(evt_obj:Object) {
trace("In change listener");
}

test1_mc.static_cb.addEventListener("change", onChangeFunc);


There are two models out there, the ASBroadcaster and the EventDispatcher, hence all the confusion... I can't even remember which is which :)