PDA

View Full Version : Using passed parameter fails


JManning
09-07-2004, 02:08 AM
Hi, I'm quite new to ActionScript and have a fairly simple task to parse an xml file and dynamically create some read-only text fields.

I have a function call that I pass the name to be used for the field and then call createTextField with that name. I then use 'with' to initialize the field's properties. When I run the Actionscript there are no errors generated but I also see no text field.

I do the same createTextField, within the function call, without the passed variable, and it works (displays) fine.

I suspect that I'm doing something wrong with using the passed variable. I've scoured (kind of) the sites that seem to focus on Flash, like this one, and nothing.

Here is a snippet of the script:


//---------------------------------
// Create Fields
//
function createField(fName, fNum, fText) {

createTextField(fName, 20, 50, 80, 100, 20);
with (fName) {
autoSize = true;
background = true;
html = true;
multiline = true;
selectable = true;
text = "0";
type = "dynamic";
wordWrap = false;
htmlText = fText;

}

trace("CreateField: name="+fName+" num="+fNum+" txt="+fText+" lNum="+_labelFieldNum);

trace("----------------------------------");
}

//---------------------------------
// XML Data stub
//
function sendItOut() {

prime = new XML();
prime = this.firstChild;

for (x=0; x<prime.childNodes.length; x++) {

var header = prime.childNodes[x].nodeName.toString();
trace(x+" header: "+header+newline);

for (z=0; z < prime.childNodes[x].childNodes.length; z++) {

var fText:String = prime.childNodes[x].childNodes[z].childNodes[0].nodeValue;
var fTag:String = prime.childNodes[x].childNodes[z].nodeName;

trace("nodeValue: "+fTag+"-"+fText+newline);
trace(x+":"+z+" data: "+prime.childNodes[x].childNodes[z].toString()+newline);

createField(fTag, fNum, fText);
}
}
}

//----------------------------------------------------- fall-through main thread
//
var Odata:XML = new XML();
Odata.ignoreWhite = true;
Odata.onLoad = sendItOut;
Odata.load("c:\\eBall.xml");

I've stripped much of the unnecessary portions of the script and included just the pertinent code. The parsing is working fine and it's only the createTextField that doesn't work. In the static version, which works, the field name is passed as a string literal "string" and the 'with' property keyword does not include the parens. I'm not sure how to do this with the passed argument and this may be the issue. If you need more info please let me know.

Thanks for any help with this problem.

JM