I’ve been asked to do a job that will grab XML data and output it with flash. The scope of the project is a little hazy as the clients are testing out if I can do it first. I believe there is no processing on the XML data, just display the XML text attribute. Scalability may be a concern, and there may be a need for different languages.
I’m comfortable using AS2, I have never used AS3. I know XML, however I haven’t used flash with XML. From some general reading, AS3 seems to be the way to go. However, my (lack of) experience in AS3 isn’t making me confident, but I’ve read that it deals with XML better.
Absolutely no idea on that!
I am a php’er by trade so dont fully understand the intricacies of AS3 yet. Most of what I have done is hacking/slashing/crapping and frankensteining mixed with a healthy dose of trial and error
That’s great, for scalability/optimization is there anything that I should keep in mind when dealing with XML?
Here’s something I’ve tried, I think I’m on the right track.
// URLLoader loads data from an external source
var xmlLoader:URLLoader = new URLLoader();
var xmlData:XML = new XML();
// Wait for the XML file to completely load
xmlLoader.addEventListener(Event.COMPLETE, LoadXML);
// call load, URLRequest loads file in entirety
xmlLoader.load(new URLRequest("passport.xml"));
function LoadXML(e:Event):void {
xmlData = new XML(e.target.data);
ParsePassport(xmlData);
}
// This function takes the XML object as an argument
function ParsePassport(passportInput:XML):void {
trace("XML Output");
trace("------------------------");
// call to ParsePassport method
var i;
i = passportInput.ENTITY.COUNTRY;
// trace(i);
if (i == "Ireland") {
hello.text = String (i);
} else {
hello.text = String ("XML Read failed");
}
}
It is surprisingly easy to keep it all tidy. This is the basic function I use
var xmlList:XML;
var xmlSource:String = 'xml/Case.xml';
urlRequest = new URLRequest(xmlSource);
urlLoader = new URLLoader();
urlLoader.addEventListener(Event.COMPLETE, xmlLoaded);
urlLoader.load(urlRequest);
function xmlLoaded(e:Event):void {
xmlList = new XML(urlLoader.data);
}
with that you can then use xmlList as the object to reference the XML data
eg:
xmlList.patient.fig[1]
my xml file (sample)
<patient>
<fig casethumb="Case_2/tn/tn_ecg.jpg" casefile="Case_2/swf/Case2.ecg.swf" txt="ECG showing increased R-wave voltages with widespread T wave changes" />
<fig casethumb="Case_2/tn/tn_00000001.jpg" casefile="Case_2/swf/Case2.1.swf" txt="Transthoracic echocardiography- Four chamber view showing severe left ventricular hypertrophy." />
</patient>
Thanks for the reassurance. With AS3 and XML, I’m presuming I’ll need to keep my code lean and optimized, that’s where my confidence lacks the most. With, code in general, there’s so many different ways to optimize, with AS3, is there many different ways to handle the data or is it pretty much only one way?