Hi all,
I am creating a crawler in actionscript and i am taking an object oriented approach, which means that i have a class which is saved as an .as file. I then call the class in a .fla file.
The problem i am facing is that i am trying to read from an external xml file in the init function and populate an array with the contents of the xml file. I then try to print the length of the array but it prints undefined.
Actually i create a function that loads the xml file and returns an xml file. I then call that function in the init function. What i did was to create an xml object and assign it to the function like so: xmlfil = view(“filename”); but it gives me undefined when i run. Please help me out.
ActionScript class
dynamic class Crawler
{
public var filename:String;
function Crawler(filename:String)
{
this.filename = filename;
}
function init()
{
var xmlfil:XML = new XML("filename");
xmlfil = view("filename");
createTextField("scroller_txt", 1, -500,100, 2000, 50);
scroller_txt.html = true;
scroller_txt.background = true;
scroller_txt.backgroundColor = 0xFDF5E6;
scroller_txt._y = 300;
trace(scroller_txt.backgroundColor);
var myArray:Array = xmlfil.firstChild.childNodes;
trace(xmlfil);
trace("the length of the array is"+ myArray.length);
for(var i=0; i<myArray.length;i++)
{
if(i%2 == 1)
{
var sped = 10;
scroller_txt.htmlText =" “+”<img src=“E:\HELENA E stuff\Helena’s Game 10-23-2006\flash\ igo.jpg”>" + myArray[1].firstChild.nodeValue;
for( m=0; m<50; m++)
{
if(m%2 == 1)
{
scroller_txt.htmlText+= “<img src=“E:\HELENA E stuff\Helena’s Game 10-23-2006\flash\ igo.jpg”>”+ myArray[m+2].firstChild.nodeValue;
}
}
scroller_txt.spacebuffer = " ";
scroller_txt.border = true;
scroller_txt.speed = sped;
myTextFormat = new TextFormat();
myTextFormat.font = “Verdana”; //this should be a string
myTextFormat.color = black;
myTextFormat.size = 13;
scroller_txt.setTextFormat(myTextFormat);
scroller_txt.spaceSize = 50;//scroller_txt.getNewTextFormat().getTextExtent(" ").width;
scroller_txt.spacesRequired = Math.ceil(scroller_txt._width/scroller_txt.spaceSize);
for (var p = 0; p<scroller_txt.spacesRequired; p++) {
scroller_txt.spacebuffer += " ";
}
scroller_txt.htmlText = scroller_txt.spacebuffer+scroller_txt.htmlText+scroller_txt.spacebuffer;
scroller_txt.hscrollInterval = function() {
if (this.hscroll == this.maxhscroll) {
this.hscroll = 0;
}
this.hscroll += 1;
};
setInterval(scroller_txt, “hscrollInterval”, 50);
}
}
}
function you (filename)
{
var i:String = filename;
}
public function view (filename):XML {
var xmlFile:XML = new XML(filename);
xmlFile.load(filename);
xmlFile.onLoad = function(bSuccess:Boolean):Void{
if (bSuccess){
trace(“loading successful”);
}
else {
trace(“Doc failed to load or parse”);
}
};
xmlFile.onLoad = init;
xmlFile.load(filename);
trace(“the init”+ xmlFile);
return xmlFile;
}
//}
}
[U].fla file
[/U]var filename:String = “E:\HELENA E stuff\Helena’s Game 10-23-2006\flash\datta.xml”;
var craw:Crawler = new Crawler(filename);
craw.view(filename);