fastweb
06-06-2005, 01:13 PM
Hi, I just added a method to a combo box (flash MX 2004 V2 component) which populates it from an xml file.
In my app all the comboBox instances need to have the same method, so I wondered if it is possible to extend the comboBox class with this method, this way I don't have to add it manually for each instance.
Here is an example of what I do for each comboBox instance:
serratura_list.dataObj = _root.xmlConfig.Configurazione[0].Configurazione_Commerciale[0].Completa[0].Serratura[0].Modello;
_root.xmlConfig.addListener(this.serratura_list);
serratura_list.onConfigChange = function() {
trace("evento onConfigChange su serratura_list ");
this.populate();
}
serratura_list.populate = function() {
trace("populate "+this._name);
var totRecords=0;
//tengo traccia dell'elemento selezionato
var selected = this.selectedItem.data;
//seleziono l'elemento corrente
var excl = "laovalue,_listeners,atrs";
//cancello tutti gli elementi
this.removeAll();
//loop nell'oggetto fino a beccare gli attributi
for (prop in this.dataObj[0]) {
if (!(this.dataObj[0][prop] instanceof Function)) {
if (excl.indexOf(prop)<0) {
_root.traceIt("property: "+prop+"("+typeof(this.dataObj[0][prop])+")");
for (nestedProp in this.dataObj[0][prop][0]) {
if (nestedProp == "atrs") {
values = new Object();
for (attributo in this.dataObj[0][prop][0][nestedProp]) {
_root.traceIt("attributo: "+attributo+"("+this.dataObj[0][prop][0][nestedProp][attributo]+")");
values[attributo]=this.dataObj[0][prop][0][nestedProp][attributo];
}
}
}
this.addItem(prop,values);
//imposto l'elemento selezionato
if (values.CodiceFiglio==selected.CodiceFiglio) {
this.selectedIndex = totRecords;
}
totRecords++;
}
}
}
}
In my app all the comboBox instances need to have the same method, so I wondered if it is possible to extend the comboBox class with this method, this way I don't have to add it manually for each instance.
Here is an example of what I do for each comboBox instance:
serratura_list.dataObj = _root.xmlConfig.Configurazione[0].Configurazione_Commerciale[0].Completa[0].Serratura[0].Modello;
_root.xmlConfig.addListener(this.serratura_list);
serratura_list.onConfigChange = function() {
trace("evento onConfigChange su serratura_list ");
this.populate();
}
serratura_list.populate = function() {
trace("populate "+this._name);
var totRecords=0;
//tengo traccia dell'elemento selezionato
var selected = this.selectedItem.data;
//seleziono l'elemento corrente
var excl = "laovalue,_listeners,atrs";
//cancello tutti gli elementi
this.removeAll();
//loop nell'oggetto fino a beccare gli attributi
for (prop in this.dataObj[0]) {
if (!(this.dataObj[0][prop] instanceof Function)) {
if (excl.indexOf(prop)<0) {
_root.traceIt("property: "+prop+"("+typeof(this.dataObj[0][prop])+")");
for (nestedProp in this.dataObj[0][prop][0]) {
if (nestedProp == "atrs") {
values = new Object();
for (attributo in this.dataObj[0][prop][0][nestedProp]) {
_root.traceIt("attributo: "+attributo+"("+this.dataObj[0][prop][0][nestedProp][attributo]+")");
values[attributo]=this.dataObj[0][prop][0][nestedProp][attributo];
}
}
}
this.addItem(prop,values);
//imposto l'elemento selezionato
if (values.CodiceFiglio==selected.CodiceFiglio) {
this.selectedIndex = totRecords;
}
totRecords++;
}
}
}
}