We help IT Professionals succeed at work.

How to access an array in one class from another

This is a Flash 8 AS2 question

Attached is testimonials.fla.  Testimonials imports a class XML_ArrayForLoop which loads external XML data and stores it in two arrays, level01Array & level02Array. The arrays are populated and verified within XML_ArrayForLoop.  

The question is how do I access the arrays from within testimonials.fla?  




import com.pricelearman.externalData.XML_ArrayForLoop;
	
	var xmlFormat:TextFormat = new TextFormat();
	xmlFormat.font = bodyFont;
	xmlFormat.color = 0xFFFFFF;
	xmlFormat.size = 12;
	
	/*
	#
	# Movie Clips
	#
	*/
	
	var id:Number = this.getNextHighestDepth();
	var pageClip:MovieClip = this.createEmptyMovieClip("pageClip_mc", id);
	pageClip._x = 0;
	pageClip._y = 125;
	
	var id:Number = pageClip.getNextHighestDepth();
	var testimonialClip:MovieClip = pageClip.createEmptyMovieClip("testimonialClip_mc", id);
	testimonialClip._x = 30;
	testimonialClip._y = 30;
	
	
	/*
	#
	# Load Content
	#
	*/
	
	_parent._parent.clipLoader.loadClip("__images/lesliePorch_475.png", leslieClip); 
	_parent._parent.clipLoader.loadClip("__images/homePhotoBar.png", photoBarClip); 
	windermereClip.attachMovie("WindermereLogo_black.ai", "windermereLogo", 1, {_x:0, _y:0});
	
	// Load XML data into arrays
	//
	var theXML:XML_ArrayForLoop = new XML_ArrayForLoop();
	var myFile:String = "__xml/testimonials.xml";
	var proxy:Boolean = false;
	theXML.doXML(myFile, proxy);
	
	// variable to hold created arrays
	//
	var quotes:Array = theXML.array01;
	var authors:Array = theXML.array02;

Open in new window

Comment
Watch Question

Top Expert 2008

Commented:
you haven't provided the attach. If you tried and could'nt change the extension to .txt.
so send me the code.

But anyway from what I see, the problem is that you are trying to acess the xml data before it is available. Everytime you request external data from flash , it comes asynchronously. So when you call doXML, there is no way it will retrieve information before the folowing lines are executed. So theXML.array01 and theXML.array02 will not have any data inside them. You should have a listener function in your new XML_ArrayForLoop(); class, like a onLoad, so you know when it happens. The final code should like like this:

var theXML:XML_ArrayForLoop = new XML_ArrayForLoop();
var myFile:String = "__xml/testimonials.xml";
var proxy:Boolean = false;
theXML.doXML(myFile, proxy);
// variable to hold created arrays
//
var quotes:Array;
var authors:Array;
thisObj = this;
theXML.onLoad = function(){
        thisObj.quotes= this.array01;
        thisObj.authors= this.array02;
}

As I don't know that class of yours I don't know what is really happening.

Juliano Polito


Author

Commented:
Juliano,

I think you are right about trying to access the arrays before they are completely loaded.  I know they are correctly loaded in XML_ArrayForLoop.  XML_ArrayForLoop is initiated from within the fla file and in the nest line of code the fla file tries to manipulate the arrays.  What seems to be needed is a way of only executing the follow-on fla actions once the arrays have completely loaded; e.g., a listener or if status=0 condition.

Here's the general idea.  I  have 3 Flash modules that work together.

Base class: (XMLLoader.as) which holds all the basic code

Parsing class: (XML_ArrayForLoop.as) that would be called by XMLLoader to supply a specific routine.  This would be selected from a library of standard routines - load into array of strings, load into an array of objects, namespaces and so on.  

An Fla File: (testimonials.fla) that would call the correct parsing class to launch the XML loading.  On a project basis I would only have to decide the parsing method and input project specific info; eg.; path to XML file.

Currently, everything works and the XML successfully loads into 2 arrays (one for each level in the XML file)  The problem is the arrays are living in the XML_ArrayForLoop.as file and I'm stumped about how to access them from within the fla file, which is needed to process them into the final product - navigation scheme, page structure, or in this case a list of testimonials and authors.

As you can probably tell I'm pretty new at AS and definitely new about how to use this forum.  I couldn't find a direct link to you, so I have attached the three AS files as 'snippets".  Hopefully they will make it through. I appreciate your help.  I can be reached at doug@pricelearman.com.
/*
	XMLLoader Class	
*/
	
	
	import mx.utils.Delegate;
	
	class com.pricelearman.externalData.XMLLoader extends XML {
		
/*
		#
		Public Variables
		#
*/
		public var theXML:XML;		// new XML object
			
/*
		#
		Private Variables
		#
*/
		private static var shttpStatus:Number;		// http error code
		private static var  sclassClip:XML;			// reference variable holding Class object
		private var __percentDone:Number;			// percentage of XMl bytes loaded
		private var __intervalID:Number;			// setInterval frequency (ms)
		private var displayXML:MovieClip;			// clip to display XML on screen
		private var progressHolder:MovieClip;		// clip holding progress info
		private var progressInfo:TextField;			// holds progress info text
		private var progressFormat:TextFormat;		// style for progress info
			
/*
		#
		Constructor
		#
*/
 
		public function XMLLoader() {
			
			// empty constructor
		
		}	// End Constructor
		
		
/*
		#
		Public Functions
		#
*/
 
		// Initiate Class
		//
		public function initXML (
								 
			 xmlFile:String,			// path to XML to be loaded
			 loadFunction:Function,		// name of function to parse XML
			 myClip:Object,				// reference to Class where XML is parsed
			 proxy:Boolean				// true if XML is from a foriegn domain
			 
		 ):Void {
			
			// create new XML Object
			//
			theXML = this;
			
			// Detect http error status
			//
			theXML.onHTTPStatus = function (httpStatus:Number) {
				
				this.shttpStatus = httpStatus;
				
			};
			
			
			// pass variables to parsXML function
			//
			this.parsXML(xmlFile,loadFunction, myClip, proxy);
		
		}	// End initXML
		
		
		// Parse XML data 
		//
		private function parsXML (
								  
			xFile:String,
			lFunction:Function,
			mClip:Object,
			proxy:Boolean
			
			): Void {
			
			
			//
			//
			theXML.onData = function (xFile:String):Boolean {
				
				trace("XML Data = "+xFile);
				trace("");
				
				// Monitor http status
				//
				if ( this.shttpStatus == undefined) {
					
					this.shttpStatus = null;
					this.httpStatusType = "Error";
					
					trace("httpStatusType = "+this.shttpStatus);
					trace("");
					
				}
				
				if (shttpStatus == "404") {
					
					getURL ("Error404.htm");
					this.httpStatusType = "Error";
					
				}
				
				
				// Process xFile, which now holds XML data, to
				// eliminate whitespace and build XML tree
				//
				if (xFile != undefined) {
					
					this.ignoreWhite = true;
					this.contentType = "text/xml";
					this.parseXML(xFile);
					
					// call onLoad event hnadler
					//
					this.loaded = true;
					this.onLoad();
					
				} else {
					
					this.loaded = false;
					return this.loaded;
					trace("XML data load has failed");
					trace("");
					
				}
				
			};
			
			
			// Set onload event handler. Transfer scope to mClip,
			// where XML data is parsed
			//
			theXML.onLoad = Delegate.create(mClip, lFunction);
			
			// verify proxy status and load XML
			//
			if(proxy) {
				
				var sendFile:LoadVars = new LoadVars();
				sendFile.sendAndLoad("proxy.php", theXML, "POST");
				
			} else {
				
				theXML.load(xFile);
						
						trace("Error Code = "+this.status);
						trace("");
						trace("	  0		File loaded and parsed successfully");
						trace("	 -2		CDATA tag not enclosed");
						trace("	 -3 	Initial XML declaration malformed");
						trace("	 -4 	DOCTYPE Declaration malformed");
						trace("	 -5 	Comment has no close syntax");
						trace("	 -6 	Element node malformed");
						trace("	 -7 	Out of memory");
						trace("	 -8 	Attribute malformed");
						trace("	 -9 	Start tag has no matching end tag");
						trace("	-10 	End tag has no matching start tag");
						trace("");
						
						if (this.status == 0) {
						
							trace("XML data loaded and parsed");
							trace("");
		
							
						} else {
							
							trace("XML parsing has failed");
							
						}
				
			}
		
			
			__intervalID = setInterval(this, "watchXMLLoad", 10, xFile);
			
			
		
		}	// End parsXML
		
		
		
		// Calculate percent of total bytes loaded
		//
		// get.percentLoaded = function(handle) {
		private function getPercentLoaded(my_clip):Number {
			
		return my_clip.getBytesLoaded()/my_clip.getBytesTotal();
		
		};
	
	
		// Set progress info visible & call showProgress()
		//
		private function watchXMLLoad(my_clip) {
			
			var perc:Number = getPercentLoaded(my_clip);
			
			if (perc>0) {
				progressHolder.visible = true;
				progressHolder.xmlProgressInfo.text = int(perc*100)+" %";
				progressHolder.xmlProgressInfo.setTextFormat(progressFormat);
				
				trace("percentLoaded = "+__percentDone+" %");
				trace("");
				
				// Call showProgress once loading has begun
				//
				showProgress(__percentDone, progressHolder);
			}
			
			if (perc==1) {
				
				progressHolder._visible = false;
				clearInterval(__intervalID);
				
			}
		
		}
		
		function showProgress(__percentDone:Number, progressHolder:MovieClip):Void {
			var barWidth:Number = __percentDone;
			progressHolder.progressInfo.text = "  Loading XML ... Please wait   "+String(Math.ceil(__percentDone))+" %";
			progressHolder.progressInfo.setTextFormat(progressFormat);
			progressHolder.clear;
				
			// Draw border
			//
			progressHolder.moveTo(0, 4);
			progressHolder.lineStyle(1, 0x000000, 100);
			progressHolder.lineTo(220, 4);
			progressHolder.lineTo(220, 24);
			progressHolder.lineTo(0, 24);
			progressHolder.lineTo(0, 4);
				
			// Draw bar
			//
			progressHolder.moveTo(120, 4);
			progressHolder.beginFill(0xCCCCCC, 80);
			progressHolder.lineTo(120+barWidth, 4);
			progressHolder.lineTo(120+barWidth, 24);
			progressHolder.lineTo(120, 24);
			progressHolder.lineTo(120, 4);
			progressHolder.endFill();
		}
		
		
	}	// End XMLLoader
 
 
/*
	XML_ForLoopArray Class
	
	*/
	
 
	import com.pricelearman.externalData.XMLLoader;
	
	class com.pricelearman.externalData.XML_ArrayForLoop {
		
		// 
		//
		public var theXML:XMLLoader;
		private var level01Array:Array = new Array();
		private var level02Array:Array = new Array();
		private var level03Array:Array = new Array();
		private var i:Number;
		
		
		// Constructor
		//
		public function ForLoop () {
		
			// empty constructor
			
		}	// End Constructor
		
		
		// Initiate loading of extenal XML file
		//
		public function doXML(myFile:String, proxy:Boolean) {
			
			theXML = new XMLLoader();
			theXML.initXML (myFile, loadXML, this, proxy);
			
		}	// End 
		
		
		private function loadXML() {
			
			// Establish the root node as first child of first child
			// since XML header is the first node
			//
			var shortNode:XMLNode = theXML.firstChild;
			var rootNode:XMLNode = shortNode;
			var countNodes:Number = rootNode.childNodes.length;
			
			trace("Root Node is = "+rootNode.nodeName);
			trace("Number of Child Nodes = "+countNodes);
			trace("");
			trace("[1][0] Value = "+rootNode.childNodes[1].childNodes[0].firstChild.nodeValue);
			trace("level01Array[1] = "+level01Array[1]);
			
			
			// Cycle through child nodes from 0 to total number
			// looking for section nodes.
			//
			for (i = 0; i < countNodes; i++) {
						
				level01Array.push(rootNode.childNodes[i].childNodes[0].firstChild.nodeValue);
				trace("level01Array[i] = "+level01Array[i]);
				trace("");
				level02Array.push(rootNode.childNodes[i].childNodes[1].firstChild.nodeValue);
				
				trace("i = "+i);
				trace("");
				
			}
			
			trace("Quotes: "+level01Array);
			trace("level01Array Length = "+level01Array.length);
			trace("");
			trace("Authors: "+level02Array);
			trace("level02Array Length = "+level02Array.length);
			trace("");
 
			
		}	// End loadXML
		
		
		public function get array01():Array {
			
			return level01Array;
			
		}	// End Get level01Array
		
		
		public function get array02():Array {
			
			return level02Array;
			
		}	// End Get level02Array
		
	}
 
 
	// testimonials.fla
 
	trace("#");
	trace("#");
	trace("Testimonials has Launched");
	trace("#");
	trace("#");
 
	import mx.utils.Delegate.*;
	import com.pricelearman.externalData.XML_ArrayForLoop;
	
	var xmlFormat:TextFormat = new TextFormat();
	xmlFormat.font = bodyFont;
	xmlFormat.color = 0xFFFFFF;
	xmlFormat.size = 12;
	
	/*
	#
	# Movie Clips
	#
	*/
	
	var id:Number = this.getNextHighestDepth();
	var pageClip:MovieClip = this.createEmptyMovieClip("pageClip_mc", id);
	pageClip._x = 0;
	pageClip._y = 125;
	
	var id:Number = pageClip.getNextHighestDepth();
	var testimonialClip:MovieClip = pageClip.createEmptyMovieClip("testimonialClip_mc", id);
	testimonialClip._x = 30;
	testimonialClip._y = 30;
	
	
	/*
	#
	# Load Content
	#
	*/
	
	_parent._parent.clipLoader.loadClip("__images/lesliePorch_475.png", leslieClip); 
	_parent._parent.clipLoader.loadClip("__images/homePhotoBar.png", photoBarClip); 
	windermereClip.attachMovie("WindermereLogo_black.ai", "windermereLogo", 1, {_x:0, _y:0});
	
	// Load XML data into arrays
	//
	var theXML:XML_ArrayForLoop = new XML_ArrayForLoop();
	var myFile:String = "__xml/testimonials.xml";
	var proxy:Boolean = false;
	theXML.doXML(myFile, proxy);
	
	// variable to hold created arrays
	//
	var quotes:Array = level01Array;
	var authors:Array = level02Array;

Open in new window

Top Expert 2008

Commented:
OK. Here it goes. I created an event handler inside the XML_ForLoopArray , that gets called whenever the load process ends, take a look at the code we call onLoad(), wich in turn is declared as a function on the class itself, it is empty cause it is meant to be overriden, AS 2 style. Then take a look at the end of the testmonial AS i put there, we wait for the onLoad to fill the arrays.
note: I haven't tested cause i don't have the .fla, but I'm sure it will work. I just copied your code to notepad, edited, and paste back, so hope everything else is intact.

Juliano Polito
/*  XMLLoader Class */
 
import mx.utils.Delegate;
	
	class com.pricelearman.externalData.XMLLoader extends XML {
		
/*
		#
		Public Variables
		#
*/
		public var theXML:XML;		// new XML object
			
/*
		#
		Private Variables
		#
*/
		private static var shttpStatus:Number;		// http error code
		private static var  sclassClip:XML;			// reference variable holding Class object
		private var __percentDone:Number;			// percentage of XMl bytes loaded
		private var __intervalID:Number;			// setInterval frequency (ms)
		private var displayXML:MovieClip;			// clip to display XML on screen
		private var progressHolder:MovieClip;		// clip holding progress info
		private var progressInfo:TextField;			// holds progress info text
		private var progressFormat:TextFormat;		// style for progress info
			
/*
		#
		Constructor
		#
*/
 
		public function XMLLoader() {
			
			// empty constructor
		
		}	// End Constructor
		
		
/*
		#
		Public Functions
		#
*/
 
		// Initiate Class
		//
		public function initXML (
								 
			 xmlFile:String,			// path to XML to be loaded
			 loadFunction:Function,		// name of function to parse XML
			 myClip:Object,				// reference to Class where XML is parsed
			 proxy:Boolean				// true if XML is from a foriegn domain
			 
		 ):Void {
			
			// create new XML Object
			//
			theXML = this;
			
			// Detect http error status
			//
			theXML.onHTTPStatus = function (httpStatus:Number) {
				
				this.shttpStatus = httpStatus;
				
			};
			
			
			// pass variables to parsXML function
			//
			this.parsXML(xmlFile,loadFunction, myClip, proxy);
		
		}	// End initXML
		
		
		// Parse XML data 
		//
		private function parsXML (
								  
			xFile:String,
			lFunction:Function,
			mClip:Object,
			proxy:Boolean
			
			): Void {
			
			
			//
			//
			theXML.onData = function (xFile:String):Boolean {
				
				trace("XML Data = "+xFile);
				trace("");
				
				// Monitor http status
				//
				if ( this.shttpStatus == undefined) {
					
					this.shttpStatus = null;
					this.httpStatusType = "Error";
					
					trace("httpStatusType = "+this.shttpStatus);
					trace("");
					
				}
				
				if (shttpStatus == "404") {
					
					getURL ("Error404.htm");
					this.httpStatusType = "Error";
					
				}
				
				
				// Process xFile, which now holds XML data, to
				// eliminate whitespace and build XML tree
				//
				if (xFile != undefined) {
					
					this.ignoreWhite = true;
					this.contentType = "text/xml";
					this.parseXML(xFile);
					
					// call onLoad event hnadler
					//
					this.loaded = true;
					this.onLoad();
					
				} else {
					
					this.loaded = false;
					return this.loaded;
					trace("XML data load has failed");
					trace("");
					
				}
				
			};
			
			
			// Set onload event handler. Transfer scope to mClip,
			// where XML data is parsed
			//
			theXML.onLoad = Delegate.create(mClip, lFunction);
			
			// verify proxy status and load XML
			//
			if(proxy) {
				
				var sendFile:LoadVars = new LoadVars();
				sendFile.sendAndLoad("proxy.php", theXML, "POST");
				
			} else {
				
				theXML.load(xFile);
						
						trace("Error Code = "+this.status);
						trace("");
						trace("	  0		File loaded and parsed successfully");
						trace("	 -2		CDATA tag not enclosed");
						trace("	 -3 	Initial XML declaration malformed");
						trace("	 -4 	DOCTYPE Declaration malformed");
						trace("	 -5 	Comment has no close syntax");
						trace("	 -6 	Element node malformed");
						trace("	 -7 	Out of memory");
						trace("	 -8 	Attribute malformed");
						trace("	 -9 	Start tag has no matching end tag");
						trace("	-10 	End tag has no matching start tag");
						trace("");
						
						if (this.status == 0) {
						
							trace("XML data loaded and parsed");
							trace("");
		
							
						} else {
							
							trace("XML parsing has failed");
							
						}
				
			}
		
			
			__intervalID = setInterval(this, "watchXMLLoad", 10, xFile);
			
			
		
		}	// End parsXML
		
		
		
		// Calculate percent of total bytes loaded
		//
		// get.percentLoaded = function(handle) {
		private function getPercentLoaded(my_clip):Number {
			
		return my_clip.getBytesLoaded()/my_clip.getBytesTotal();
		
		};
	
	
		// Set progress info visible & call showProgress()
		//
		private function watchXMLLoad(my_clip) {
			
			var perc:Number = getPercentLoaded(my_clip);
			
			if (perc>0) {
				progressHolder.visible = true;
				progressHolder.xmlProgressInfo.text = int(perc*100)+" %";
				progressHolder.xmlProgressInfo.setTextFormat(progressFormat);
				
				trace("percentLoaded = "+__percentDone+" %");
				trace("");
				
				// Call showProgress once loading has begun
				//
				showProgress(__percentDone, progressHolder);
			}
			
			if (perc==1) {
				
				progressHolder._visible = false;
				clearInterval(__intervalID);
				
			}
		
		}
		
		
 
		function showProgress(__percentDone:Number, progressHolder:MovieClip):Void {
			var barWidth:Number = __percentDone;
			progressHolder.progressInfo.text = "  Loading XML ... Please wait   "+String(Math.ceil
 
(__percentDone))+" %";
			progressHolder.progressInfo.setTextFormat(progressFormat);
			progressHolder.clear;
				
			// Draw border
			//
			progressHolder.moveTo(0, 4);
			progressHolder.lineStyle(1, 0x000000, 100);
			progressHolder.lineTo(220, 4);
			progressHolder.lineTo(220, 24);
			progressHolder.lineTo(0, 24);
			progressHolder.lineTo(0, 4);
				
			// Draw bar
			//
			progressHolder.moveTo(120, 4);
			progressHolder.beginFill(0xCCCCCC, 80);
			progressHolder.lineTo(120+barWidth, 4);
			progressHolder.lineTo(120+barWidth, 24);
			progressHolder.lineTo(120, 24);
			progressHolder.lineTo(120, 4);
			progressHolder.endFill();
		}
		
		
	}	// End XMLLoader
 
 
/*
	XML_ForLoopArray Class
	
	*/
	
 
	import com.pricelearman.externalData.XMLLoader;
	
	class com.pricelearman.externalData.XML_ArrayForLoop {
		
		// 
		//
		public var theXML:XMLLoader;
		private var level01Array:Array = new Array();
		private var level02Array:Array = new Array();
		private var level03Array:Array = new Array();
		private var i:Number;
		
		
		// Constructor
		//
		public function ForLoop () {
		
			// empty constructor
			
		}	// End Constructor
		
		
		// Initiate loading of extenal XML file
		//
		public function doXML(myFile:String, proxy:Boolean) {
			
			theXML = new XMLLoader();
			theXML.initXML (myFile, loadXML, this, proxy);
			
		}	// End 
		
		
		private function loadXML() {
			
			// Establish the root node as first child of first child
			// since XML header is the first node
			//
			var shortNode:XMLNode = theXML.firstChild;
			var rootNode:XMLNode = shortNode;
			var countNodes:Number = rootNode.childNodes.length;
			
			trace("Root Node is = "+rootNode.nodeName);
			trace("Number of Child Nodes = "+countNodes);
			trace("");
			trace("[1][0] Value = "+rootNode.childNodes[1].childNodes[0].firstChild.nodeValue);
			trace("level01Array[1] = "+level01Array[1]);
			
			
			// Cycle through child nodes from 0 to total number
			// looking for section nodes.
			//
			for (i = 0; i < countNodes; i++) {
						
				level01Array.push(rootNode.childNodes[i].childNodes[0].firstChild.nodeValue);
				trace("level01Array[i] = "+level01Array[i]);
				trace("");
				level02Array.push(rootNode.childNodes[i].childNodes[1].firstChild.nodeValue);
				
				trace("i = "+i);
				trace("");
				
			}
			
			trace("Quotes: "+level01Array);
			trace("level01Array Length = "+level01Array.length);
			trace("");
			trace("Authors: "+level02Array);
			trace("level02Array Length = "+level02Array.length);
			trace("");
			/***************************************/
			/**************HERE***************/				/**************************************/
 			//HERE WE CALL OUR OWN EVENT HANDLER ONLOAD
			onLoad()
			
		}	// End loadXML
		
		//THIS IS OUR EVENT HANDLER ONLOAD - IT IS EMPTY CAUSE IT 
		//WILL BE OVERIDEN OUTSIDE TO NOTIFY ABOUT THE LOAD
		public function onLoad(){
 
		}
		public function get array01():Array {
			
			return level01Array;
			
		}	// End Get level01Array
		
		
		public function get array02():Array {
			
			return level02Array;
			
		}	// End Get level02Array
		
	}
 
/*
	XMLLoader Class	
*/
	
	
	
 
 
 
 
 
	// testimonials.fla
 
	trace("#");
	trace("#");
	trace("Testimonials has Launched");
	trace("#");
	trace("#");
 
	import mx.utils.Delegate.*;
	import com.pricelearman.externalData.XML_ArrayForLoop;
	
	var xmlFormat:TextFormat = new TextFormat();
	xmlFormat.font = bodyFont;
	xmlFormat.color = 0xFFFFFF;
	xmlFormat.size = 12;
	
	/*
	#
	# Movie Clips
	#
	*/
	
	var id:Number = this.getNextHighestDepth();
	var pageClip:MovieClip = this.createEmptyMovieClip("pageClip_mc", id);
	pageClip._x = 0;
	pageClip._y = 125;
	
	var id:Number = pageClip.getNextHighestDepth();
	var testimonialClip:MovieClip = pageClip.createEmptyMovieClip("testimonialClip_mc", id);
	testimonialClip._x = 30;
	testimonialClip._y = 30;
	
	
	/*
	#
	# Load Content
	#
	*/
	
	_parent._parent.clipLoader.loadClip("__images/lesliePorch_475.png", leslieClip); 
	_parent._parent.clipLoader.loadClip("__images/homePhotoBar.png", photoBarClip); 
	windermereClip.attachMovie("WindermereLogo_black.ai", "windermereLogo", 1, {_x:0, _y:0});
	
	// Load XML data into arrays
	//
	var theXML:XML_ArrayForLoop = new XML_ArrayForLoop();
	var myFile:String = "__xml/testimonials.xml";
	var proxy:Boolean = false;
	theXML.doXML(myFile, proxy);
 
	// variable to hold created arrays
 
	/***************************************/
	/**************HERE***************/	/**************************************/
	var quotes:Array = level01Array;
	var authors:Array = level02Array;
	var thisObj = this;
	theXML.onLoad = function(){
		thisObj.quotes = this.level01Array;
		thisObj.authors = this.level02Array;
		//here this keyword means the object theXML itself
		//that is why I used the reference thisObj, to get outside scope
	}
	

Open in new window

Top Expert 2008

Commented:
UPDATE: Above as the code snippet section has line numbers, I'll write here the lines where you should look :

Line 345 - Call the event to notify - event dispatching
Line 352 - handler place holder
Line 435 - 443 - use the xml onload to wait for the result

Just keep in mind what I told you. Every external communication from flash is not synchronous, so you always need to use a event listener or some kind of event to respond the completion of the async process.

Juliano Polito

Author

Commented:
I'm not sure how your theXML.onLoad function relates to the theXML.onload on line 146.  Do we need both?  I still get undefined for the quote & author arrays.  I have attached a piece of the XML file if you want to test.  Thanks
<?xml version="1.0" encoding="ISO-8859-1"?>
 
<testimonials>
	<quote id = "1">
		<copy description="copy ">Working with Leslie was the most positive experience we've had; not only in thew Real Estate industry. but with any sales or service transaction. She is extremely responsive and knowledgeable regarding real estate in our market. Her negotiating skills are second to none.</copy>
		<author description="author ">The Powells</author>
	</quote>
	<quote id = "2">
		<copy description="copy ">Leslie, it was a pleasure working with you. You have a very pleasant, positive and professional attitude and seek to please your clients in anyway you can.  We will recommend your services and look forward to working with you again in the future.</copy>
		<author description="author ">The Roses</author>
	</quote>
	<quote id = "3">
		<copy description="copy ">Leslie and her excellent assistant Danielle showed me what committed service is all about. Their patience and expertise were invaluable and continued throughout the entire transaction.  I felt we were a team in this process and it was rewarding to know that my interests were so well represented.</copy>
		<author description="author ">G. Beeman</author>
</testimonials>

Open in new window

Top Expert 2008

Commented:
I'll test for you
Top Expert 2008

Commented:
I found the problem. As I did not test and have not looked through your code, have not seen that your properties level01Array and so on, were private, so it was not possible to access those outside the class. get my attached file to see it working. In my example I extracted the packge information of your classes, so I did not have to create folders. ;)
Top Expert 2008

Commented:
oops, file is here - change extension from .pdf to .zip
xmlloader.zip.pdf

Author

Commented:
Your solution feels right.  I won't be able to try it out until tomorrow (2/6).  Sorry for the delay, but duty calls. Your effort on this is really appreciated and I will respond tomorrow.

Thanks
Top Expert 2008
Commented:
did it work?

Author

Commented:
Thanks for your help and hanging in there with me. This is my final code, and it traces out OK.

      
      // Load XML data into arrays
      //
      var theXML:XML_ArrayForLoop = new XML_ArrayForLoop();
      var myFile:String = "__xml/testimonials.xml";
      var proxy:Boolean = false;
      theXML.doXML(myFile, proxy);
      
      var thisObj:Object = this;
      //
      //
      var quotes:Array = thisObj.theXML.array01;
      var authors:Array = thisObj.theXML.array02;
      
      // Verify arrays
      //
      trace("quotes[2] = "+theXML.array01[2]);
      trace("authors[0] = "+theXML.array02[0]);
Top Expert 2008

Commented:
hope you understood everything ! thanks and just call me if you need any help

Author

Commented:
I don't know how to get your number.  This is me doug@pricelearman.com
Top Expert 2008

Commented:
you can reach me here. just send a post to this question letting me know of a new question of yours. also if you want professional services, reach me at julianopolito at gmail

Author

Commented:
Ok.  I have posted another question here.  I also emailed you at digitalbug.  I have a small media company in Seattle area.  I see Flash as the future for design driven sites for a host of reasons.  So, I made the 'executive' decision to develop all future sites in Flash.  As a result, I'm learning AS 2 on the fly while doing live projects.  A bit steeper curve than I anticipated, and I could use professional services on problem-by-problem basis.
Top Expert 2008

Commented:
I'm in brazil. Here I'm a consultant and adobe certified instructor. I also have a small company for web development. anytime you need send me email and we can talk about that partnership.

Explore More ContentExplore courses, solutions, and other research materials related to this topic.