CK
You have a scope problem. elements_arr is defined within the onLoad handler so it won't be accessible from outside (i.e. from your assignText() function). You'd better use the static mx.utils.Delegate class to handle the onLoad event in an easier manner:

import mx.utils.Delegate;

var elements_arr:Array = [];
var aquentDoc:XML = new XML();
aquentDoc.ignoreWhite = true;
aquentDoc.onLoad = Delegate.create(this, this.onAquentDocLoad);
aquentDoc.load("xml url here");

function onAquentDocLoad(success:Boolean):Void {

  // ... check for success, XML validation & parsing...

  // now fill your array (elements_arr is available)
  elements_arr = aquentDoc.firstChild.childNodes;
  for (var i = 0; i < elements_arr.length; i++) {
       if (elements_arr[i].attributes["id"] != null) {
          var headers = elements_arr[i].attributes["id"];
       } else {
          var content = elements_arr[i];
       }
   }
   // the array is filled, you can call assignText()
   assignText();
}

function assignText() {
  for (var p in this) {
    if (this[p] instanceof TextField) {
      trace("found "+this[p]._name);
    }
    if(this[p]._name == "header01_text"){
      this[p].text=elements_arr[i].attributes["id"];
  }
}


Hope it helps..
Julien

CK a écrit :
Hi,

An attempt to dynamically assign text gathered from XML nodes has me stumped. I've the text field instances, but am at a loss how to proceed. Any help would be appreciated.

Code:
//Create XML Object
var aquentDoc:XML = new XML();
aquentDoc.ignoreWhite = true;
//event handler
aquentDoc.onLoad = function(success:Boolean) {
   if (!success) {
      trace("Failure Loading aquentDoc XML");
      return;
   }
   //validating the xml file
   if (this.status != 0) {
      trace("This xmlObject is not well-formed: "+this.status);
      return;
   }
   //Error check - xml data okay!
   if (this.firstChild.nodeName.toLowerCase() != "aquentdoc") {
      trace("Unexpected XML data: "+this.firstChild.nodeName);
      return;
   }
   //Extract header nodes into an array.
   var elements_arr = this.firstChild.childNodes;
   for (var i = 0; i<elements_arr.length; i++) {
      //trace(elements_arr[i]);
      if (elements_arr[i].attributes["id"] != null) {
         var headers = elements_arr[i].attributes["id"];
         //trace(headers);
      } else {
         var content = elements_arr[i];
         //trace(content);
      }
   }
};

Code:
//Displays the text fields correctly.
function assignText() {
   for (var p in this) {
      if (this[p] instanceof TextField) {
         //Show each field's name
         trace("found "+this[p]._name);
      }
   }
}

Code:
//Failed attempt at assigning text.
//This should be called from inside the onLoad handler.
function assignText() {
   for (var p in this) {
      if (this[p] instanceof TextField) {
         //Show each field's name
         trace("found "+this[p]._name);
      }
if(this[p]._name == "header01_text){
 this[p].text=elements_arr[i].attributes["id"];
}
}_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com


_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to