-
[F8] first class variable troubles
I'm trying to get a class working in ActionScript 2 and having real problems
hopefully someone can help me with the following code
class library.classes.XML_Loader {
var _file:String;
var data_xml:Object;
var i:Number;
var _targetText:String;
var target:String;
var sortItOut:String = "sorted";
//
public function XML_Loader(file,targetText) {
_file = file;
_targetText = targetText;
}
public function update() {
trace("loading xml file = " + _file);
data_xml = new XML();
data_xml.ignoreWhite = true;
data_xml.onLoad = loadData;
data_xml.load(_file);
//
function sendData() {
trace("this is..." + sortItOut);
}
function loadData(success) {
trace("xml loaded");
data_xml = this.toObject();
trace(data_xml.siteMenu.button.length);
target = "button_";
for(i=0; i<data_xml.siteMenu.button.length +1; i++) {
_root[target + i]._textField.text = data_xml.siteMenu.button[i-1].buttonLabel;
}
}
//
XML.prototype.toObject = function () {
var $xparse = function (n) {
var o = new String (n.firstChild.nodeValue), s, i, t
for (s = (o == "null") ? n.firstChild : n.childNodes[1]; s !=
null; s = s.nextSibling) {
t = s.childNodes.length > 0 ? arguments.callee (s) :
new String (s.nodeValue)
for (i in s.attributes) t[i] = s.attributes[i]
if (o[s.nodeName] != undefined) {
if (!(o[s.nodeName] instanceof Array)) o
[s.nodeName] = [o[s.nodeName]]
o[s.nodeName].push (t) }
else o[s.nodeName] = t }
return o }
return $xparse (this)
}
}
}
The problem is that i can't get info (variables) into (or out of) the loadData(success) function.
I've tried just about every workaround i can think of, but this time i'm well and truly stumped.
One solution would be to move the for-loop out of the function, but then it doesn't recieve the xml to spread around the site.
Thanks in advance to anyone who can shed some light on this!
-
I've done some more work on the code (ahem) and framed a clearer question.
What i want to know is... how do i get variables into the loadData(success) function?
class library.classes.XML_Loader {
var _file:String;
var data_xml:Object;
var i:Number;
var _targetText:String;
var target:String;
var sortItOut:String = "sorted";
//
public function XML_Loader(file,targetText) {
_file = file;
_targetText = targetText;
}
public function update() {
trace("loading xml file = " + _file);
data_xml = new XML();
data_xml.ignoreWhite = true;
data_xml.onLoad = loadData;
data_xml.load(_file);
//
function loadData(success) {
trace("xml loaded");
data_xml = this.toObject();
trace(data_xml.siteMenu.button.length);
// target = "button_";
target = _targetText;
trace("this is..." + sortItOut);
for(i=0; i<data_xml.siteMenu.button.length +1; i++) {
_root[target + i]._textField.text = data_xml.siteMenu.button[i-1].buttonLabel;
}
}
//
XML.prototype.toObject = function () {
var $xparse = function (n) {
var o = new String (n.firstChild.nodeValue), s, i, t
for (s = (o == "null") ? n.firstChild : n.childNodes[1]; s !=
null; s = s.nextSibling) {
t = s.childNodes.length > 0 ? arguments.callee (s) :
new String (s.nodeValue)
for (i in s.attributes) t[i] = s.attributes[i]
if (o[s.nodeName] != undefined) {
if (!(o[s.nodeName] instanceof Array)) o
[s.nodeName] = [o[s.nodeName]]
o[s.nodeName].push (t) }
else o[s.nodeName] = t }
return o }
return $xparse (this)
}
}
}
Let me know if i'm missing something obvious here (i've tried everything) or if you need more information.
Cheers for your help with this (he says hopefully)
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|