Hello, I am actually discovering Classes.
I try to make a class that reads out an XML file and than converts it into arrays.
the array is well created in the class file, but I can’t send it back to the swf correctly: it only duplicates the first item of the array in an infinite loop, but when I trace it into the class the output displays it right…
Can someone help me with this issue?
with this code I call the class:
var myProduct:Product = new Product("gallery.xml");
this.onEnterFrame = function() {
trace(myProduct.getArray());
if (myProduct.getArray() != undefined) {
delete this.onEnterFrame;
}
};
and this is the class I use:
class Product {
public var productsXml:XML;
public var catArray:Array = new Array();
public var myArr:Array = new Array();
function Product(targetXmlStr:String) {
var thisObj:Product = this;
var prodXml:XML = new XML();
prodXml.ignoreWhite = true;
prodXml.onLoad = function(success:Boolean) {
if (success) {
thisObj.productsXml = this;
thisObj.getArray();
} else {
trace("error loading XML");
}
};
prodXml.load(targetXmlStr);
}
function getArray() {
var i:Number;
var j:Number;
var fNnum:Number = this.productsXml.firstChild.childNodes.length;
var mItemArray:Array = new Array();
for (i=0; i<fNnum; i++) {
var itNum:Number = this.productsXml.firstChild.childNodes*.childNodes.length;
catArray.push(this.productsXml.firstChild.childNodes*.attributes.name);
mItemArray.push(this["itemArray"+i]=new Array());
for (j=0; j<itNum; j++) {
var titleName:String = this.productsXml.firstChild.childNodes*.childNodes[j].attributes.title;
var picPathName:String = this.productsXml.firstChild.childNodes*.childNodes[j].attributes.main;
var thumbPathName:String = this.productsXml.firstChild.childNodes*.childNodes[j].attributes.thmb;
mItemArray*.push({tit:titleName, pic:picPathName, thumb:thumbPathName});
if (j == itNum-1) {
return catArray.length
}
//if
}
//for
}
//for
}
}