I am looking for a way to use the least amount of code to make my functionality work correctly.
IN THE FLA:
import flash.events.*;
import XMLPackage.XMLLoader;
var loadXML:XMLLoader = new XMLLoader("_XML/MainMenu.xml");
stage.addEventListener (Event.ENTER_FRAME, completeListener);
function completeListener (eo:Event)
{
try
{
loadXML.getDataNow ();
stage.removeEventListener (Event.ENTER_FRAME, completeListener);
trace (loadXML.getDataNow());
}
catch (error:TypeError)
{//Error info here}
}
IN THE PACKAGE:
package XMLPackage
{
import flash.display.*;
import flash.events.*;
import flash.net.*;
import flash.utils.*;
//Demonstrates the code required to load eternnal XML
public class XMLLoader extends Sprite
{
// The variable to which the loaded XML will be assigned
private var temporaryXMLName:XML;
private var XMLdataa:XML;
// The object used to load the XML
private var urlLoader:URLLoader;
//Constructor
public function XMLLoader (XMLPATHNAME:String)
{
// Specify the location of the external XML
var urlRequest:URLRequest = new URLRequest(XMLPATHNAME);
// Create an object that can load the external text data
urlLoader = new URLLoader();
// Register to be notified when the XML finishes loading
urlLoader.addEventListener (Event.COMPLETE, completeListener);
// Load the XML
urlLoader.load(urlRequest);
}
//Method invoked automatically when the XML finishes loading
public function completeListener (eo:Event):void
{
try
{
// The String containing the loaded XML is assigned to the URLLoader
// object's date variable(i.e., urlLoader.data). To create a new XML
// instance from that loaded string, we pass it to the XML constructor
temporaryXMLName = new XML(urlLoader.data);
//trace(temporaryXMLName.toXMLString());
// Display the loaded XML, now converted to an XML object
}
catch (error:TypeError)
{
// If we get here, that means the downloaded text could
// not be converted into an XML instance, probably because
// it is not formatted correctly
trace ( "Could not parse text into XML" );
trace ( error.message);
}
}
public function getDataNow():String{
return temporaryXMLName.toXMLString();
}
}
}
My orig intention was to make a call with the fewest lines possible from the .FLA
I was hoping to say something along the lines of:
import XMLPackage.XMLLoader;
var loadXML:XMLLoader = new XMLLoader("_XML/MainMenu.xml");
trace(loadXML);
unfortuniatly, I can’t because the trace is occurring before the
urlLoader.addEventListener (Event.COMPLETE, completeListener);
finishes loading my XML File.
Please help.