Pasting the entire class....need help.
I am simply trying to replace AS2's onLoad(success) action in AS3 and struggling to get the object passed to the new function.
The last two functions loadXML() and displayXML() are where my problem lies. How do I get the XML data into displayXML? If I use event.target.data it comes as a String and I can't parse it as XML. dataXML doesn't show up as anything in the new function. And if I parse it in the loadXML function it is not always available and I want the COMPLETE to happen first.
following the trace commands: event.target.data: shows the data in the Output window but it's a string because I've also tried dataXML = event.target.data; or dataXML = XML(e.t.d) and = new XML(e.t.d) etc......but I get errors because it is a String.
How do I pass the object in the COMPLETE listener? I'm a dumbass.
package as3 {
import flash.display.MovieClip;
import flash.display.StageScaleMode;
import flash.display.StageAlign;
import flash.events.Event;
import flash.net.URLLoader;
import flash.net.URLRequest;
import flash.text.TextField;
import flash.xml.XMLDocument;
public class Portal extends MovieClip
{
var dataXML:XML;
var xmlURL:String;
var dataXMLURL:URLRequest;
var xmlLoader:URLLoader;
public function Portal()
{
alignCentre();
loadXML();
}
public function alignCentre()
{
stage.scaleMode = StageScaleMode.EXACT_FIT;
stage.align = StageAlign.TOP;
}
public function loadXML()
{
dataXML = new XML();
xmlURL = "xml/portal.xml";
dataXMLURL = new URLRequest(xmlURL);
xmlLoader = new URLLoader(dataXMLURL);
dataXML = XML(xmlLoader.data);
xmlLoader.addEventListener(Event.COMPLETE, displayXML);
}
public function displayXML(event:Event)
{
trace(event.target.data);
trace(dataXML);
}
}
}
No need to examine the event - your loader is accessible as a property of the class. If you had declared it local to loadXML()... well, that'd be a different story. public function displayXML(event:Event) {
// trace(event.target.data);
**dataXML = XML(xmlLoader.data);**
trace(dataXML);
}
tried that too before.....and got this error:
no matter what i try as far as accessing dataXML as an XML Object, this is the most common error.
TypeError: Error #1088: The markup in the document following the root element must be well-formed. at as3::Portal/displayXML() at flash.events::EventDispatcher/dispatchEventFunction() at flash.events::EventDispatcher/dispatchEvent() at flash.net::URLLoader/onComplete()
Howzabout this: dataXML = xmlLoader.data as XML;
OFFS
I'm a retard. Thanks br. It came as a string because I had not properly contained my tag IDing the app before my .