I am working a xml-loader class. My aim is to split xml-loading process to two different packages.[INDENT] 1. XMLLoader.as load data from external xml files.
2. XMLProcessor.as stores the xml-data to the array for the further use.
3. Both packages are controlled by DocumentClass.as.
4. ContentMOV.fla is completely without code.
[/INDENT]Tree hierarchy is following: quest01/website/classdocs[INDENT] 1. ContentMOV.fla is in quest01 folder,
2. DocumentClass.as is in website folder, and
3. XMLLoader.as and XMLProcessor.as are both in classdocs folder.
[/INDENT]The DocumentClass path in fla-file is website.DocumentClass. “Browse to Path” is set from Edit/Preferences/ Language: ActionScript 3.0 Settings… to one folder before quest01 folder.
I have little experience on Actionscript 3 programming, but I just recently decided start working only with class-files. However, I am more familiar with visual basic programming (in Excel environment) and that affects quite much, how I try to approach to find solutions for programming issues. So for example, I am used to work with Global variables, but it seems that these don’t work in AS3.
Currently, the XMLLoader program opens the xml file and parse it to string. However, I am completely out of idea, how I can pass XMLDocument to the DocumentClass or XMLProcessor package. For example, I have tried following in DocumentClass:[INDENT] var XMLDocToEdit:xmlDocument = new xmlDocument();
XMLDocToEdit.xmlDocument();
[/INDENT]However, these lines cause two errors in compiler:[INDENT] 1046: Type was not found or was not a compile-time constant: xmlDocument.
1180: Call to a possibly undefined method xmlDocument.
[/INDENT]DocumentClass.as is now as follows:
package website {
import flash.display.Sprite;
import flash.display.*;
import flash.events.*;
import flash.xml.XMLDocument;
import flash.xml.XMLNode;
mport flash.xml.XMLNodeType;
import quest01.website.classdocs.XMLLoader;
import quest01.website.classdocs.XMLProcessor;
// folder.folder.folder.classname
public class DocumentClass extends Sprite {
public function DocumentClass() {
var loadContent:XMLLoader = new XMLLoader("xml/questionnaire01.xml");
loadContent.addEventListener("xmlParsed", callbackHandler);
function callbackHandler(event:Event) {
trace("MovieController: XML Data Loading Complete!");
// var XMLDocToEdit:xmlDocument = new xmlDocument();
// XMLDocToEdit.xmlDocument();
}
}
} // public Class ends
} // package ends
XMLLoader.as :
package quest01.website.classdocs {
import flash.xml.XMLDocument;
import flash.xml.XMLNode;
import flash.xml.XMLNodeType;
import flash.events.*;
import flash.display.MovieClip;
import flash.net.URLRequest;
import flash.net.URLLoader;
import flash.display.Sprite;
public class XMLLoader extends EventDispatcher {
// VARIABLES
private var XMLData_array:Array;
private var xmlData:XML;
private var xmlLoader:URLLoader;
private var XMLUrlReq:URLRequest;
private var XML_URL:String;
public var xDoc:XMLDocument;
public function XMLLoader(url:String) {
XMLData_array = new Array;
xmlData = new XML();
XML_URL = url;
xmlLoader = new URLLoader();
trace("URL: ", url);
XMLUrlReq = new URLRequest(XML_URL);
xmlLoader = new URLLoader(XMLUrlReq);
xmlData.ignoreWhitespace = true;
xmlLoader.addEventListener(Event.COMPLETE, completeHandler);
xmlLoader.addEventListener(IOErrorEvent.IO_ERROR, handleError);
}
public function completeHandler(e:Event):void {
xmlData = new XML(e.target.data); // stores loaded xmlData
trace(xmlData); // shows the complete xml-file
xDoc = new XMLDocument();
xDoc.ignoreWhite = true;
xDoc.parseXML(xmlData.toXMLString());
trace(xDoc.firstChild.childNodes[0]);
dispatchEvent(new Event("xmlParsed"));
}
private function handleError(event:IOErrorEvent):void {
trace("Error loading XML");
}
public function xmlDocument():XMLDocument {
return xDoc;
}
} // Class ends
} // package ends
So the questions again are:[INDENT] 1. How I can transfer variables from packages to the packages? What is the best practice for that?
2. Is there some kind of option to build “global” variable to store XMLDocument?
[/INDENT]Best Regards
Juno77