By the way....

My previous checkLoad function is wrong... this one is ok:

function checkLoad(dx, oldVal, newVal)
{
if(newVal)
{
 trace(xml_file.loaded);
 trace(xml);
 xml = xml_file.getXML();
 trace(xml);
 trace(xml_file.loaded);
}
}

----- Original Message ----- From: "Michel Scoz" <[EMAIL PROTECTED]>
To: "Flashcoders mailing list" <flashcoders@chattyfig.figleaf.com>
Sent: Wednesday, August 09, 2006 1:36 PM
Subject: [Flashcoders] Why in the world my class is tracing false?!?!


Hi all... now i dont get it...
I have a class in AS2 that parses a XML and returns an array of it, but I dont get why in this !@&¨%!@&¨%! it returns false when loaded!!

I have this var...
public  var loaded:Boolean;

In class Constructor I have this...
this.loaded = false;

Then Ii do in my FLA:
trace(xml_file.loaded) // returns false, witch is OK

After my class populates the array with the XML content it changes this 'loaded' boolean var like this:
this.loaded = true;

Then i do in my FLA it returns UNDEFINED just after any change I do this var..

Please help, I'm clueless on this one....
Try yourself:

parseXML.as
--------------
import mx.utils.Delegate;

class parseXML
{
//attributes
private var _xml:XML;
private var xml_result:Array = new Array();
public  var loaded:Boolean;

//constructor
public function parseXML(file:String)
{
 this._xml = new XML();
 this._xml.ignoreWhite = true;
 this._xml.load(file);
 this._xml.onLoad = Delegate.create(this, dataLoaded);
 this.loaded = false;
}

// Verify if the XML was loaded or not
private function dataLoaded(sucess:Boolean):Void
{
 if (sucess)
 {
  populateArray(this._xml, this.xml_result);
  this.loaded = true;
 } else
 {
  trace("invalid xml file");
 }
}

// Populates an array with the contents of the XML
private function populateArray(localXML, array):Void
{
 var i:Number;
 if(localXML.childNodes[0].nodeValue != null)
 {
  array.push(localXML.childNodes[0].nodeValue);
 } else
 {
  for(i = 0; i < localXML.childNodes.length; i++)
  {
   array[i] = new Array();
   populateArray(localXML.childNodes[i], array[i]);
  }
 }
}

// Returns the populated array
public function getXML():Array
{
 return this.xml_result;
}
}
// end
===================================

FLA file
--------

stop();

var xml:Array = new Array();
var xml_file:parseXML = new parseXML("xml.xml");

fscommand("allowscale", false);

xml_file.watch("loaded", checkLoad);

function checkLoad(dx, oldVal, newVal)
{
if(newVal)
{
 trace(xml_file.loaded);
 trace(xml);
 xml = xml_file.getXML();
 trace(xml);
 trace(xml_file.getLoaded());
}
}
_______________________________________________
Flashcoders@chattyfig.figleaf.com
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


_______________________________________________
Flashcoders@chattyfig.figleaf.com
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