Tengo un ComboBox que se encarga de cargar un XML.
A este lo cargo asi:
Código ActionScript :
// import this so it can be used to set the scope of the combobox listener and the xml onload routine import mx.utils.Delegate; // declare variables var people:Array; var update:String; var dirpath:String; // create a new color object to associate with the bgcolor movieclip var bgcol:Color; // set up the XML instance var peoplexml:XML = new XML(); // initialize items on stage _global.style.setStyle("fontFamily", "Verdana"); _global.style.setStyle("fontSize", 10); // define what should happen when the XML loads // (read data into update, dirpath, and people variables) function onXmlLoaded(success:Boolean) { if (success) { // make a handle to the root node in the xml var mainnode:XMLNode = peoplexml.firstChild; update = mainnode.attributes.lastupdate; dirpath = mainnode.attributes.dir; // set up an array of all person nodes var peoplenodes:Array = peoplexml.firstChild.childNodes; for (var i:Number = 0; i < peoplenodes.length; i++) { // for each person node: var personnode:XMLNode = peoplenodes[i]; people.push( {i:i+1, pname:personnode.attributes.name, bgcolor:parseInt(personnode.attributes.bgcolor, 16), photo:personnode.attributes.photo, bgswf:personnode.childNodes[0].attributes.url, desc:personnode.childNodes[1].firstChild.nodeValue, links:personnode.childNodes[2].firstChild.nodeValue }); } // data is all read and put in the right place -- now setup the screen // using this data setup(); } else { trace('error reading XML'); } } function setup() { // set up chooseperson dropdown chooseperson.labelField = "pname"; chooseperson.dataProvider = people; chooseperson.addEventListener("change", Delegate.create(this, loadScreen)); } function loadScreen(evt:Object) { var thisitem:Object = evt.target.selectedItem; ta.text = thisitem.desc; ta.vPosition = 0; bgcol.setRGB(thisitem.bgcolor); } function init() { // initialize the people array people = [{pname:"Elije una opcion"}]; // set up the xml instance to ignore whitespace between tags peoplexml.ignoreWhite = true; // set the scope of the onLoad function to the main timeline, not peoplexml peoplexml.onLoad = Delegate.create(this, onXmlLoaded); // initialize the bgcol color variable by associating it with the background movieclip bgcol = new Color(bgcolor); // start the xml loading peoplexml.load("datos.xml"); } init();
Después mediante este código:
Código ActionScript :
alabrir = new Object(); alabrir.change = function(evento) { campo.text =(chooseperson.value); } chooseperson.addEventListener("change", alabrir);
Le indico que al cambiar una opción del ComboBox realice una acción. Como verán estoy intentando que dentro de un campo dinámico se escriba el valor del ComboBox que seleccione... Pero no funciona, me dice Undefined. .
Gracias.