I'm not quite that new, but I think I can tackle this issue.
onLoad is in a function because the actual load takes place asynchronously.
If you put another statement immediately after the external_xml.load it would execute (probably) before the xml finished loading. To resolve your issue I'd move the assignment of the onLoad handler (external_xml.onLoad = function...) to above where you call the load method. The trace(myXML) is displaying nothing because the .load hasn't finished yet. It's a annoyance at first that Flash does these thing aync but if you've got 3 xml files to load its lots faster to have them going in parallel. Having tried to wrap my head around java threads this multithreading interface is a dam' site easier.
Scott Haneda wrote:
Hi, downloaded Flash, 1st post! w00t! need to work out a small project.  I
have experience in programming, not specifically OOP, and actionscript seems
to be very OOP.  I few questions:

I am loading up some XML per an example:
//ignore whitespace
XML.prototype.ignoreWhite = true;

//create variable and new XML Object
var external_xml:XML = new XML();

//variable loads external XML file
external_xml.load("example1.xml");

//trace if loaded, or not
external_xml.onLoad = function(success:Boolean) {
   if (success) {
     trace("xml loaded successfully.");
     var myXML = external_xml;
   } else {
     trace("xml failed to load.");
} };

trace(myXML);
What I don't get, it why this needs to be in a function, my experice tells
me you use functions for things you may otherwise need to use again, either
putting the in a file elsewhere, whatever.  It makes no sense to me to
functionize the reading in of XML, why not just approach it procedurally?

And, as you can see, my trace(myXML); does not work, so how would I access
the XML data outside the function, is there a "local" keyword I am not
finding?

Finally, As for details on what I need to do, to start, as a way to learn
this, I want to get a trace of something to happen:

Load in this XML file:
<camps sport="Tennis">
    <state name="California" cc="3" url="a"/>
    <state name="Oregon" cc="13" url="b"/>
    <state name="Washington" cc="2" url="c"/>
</camps>


I have that much working, I can not figure out how to access each item as of
yet, but did have a plan.  Of course, there will be 50 items in that XML
file.

Each item eventually needs to be hooked up to a map, so each state can some
coloring based on the cc value, and if there is a value for a, I can take
them to that url.

I was going to iterate the XML, and create an assoc array, in which I could
then simply call out each state name, and hopefully get to its parameters.
I can then learn how to hook those  up to each state on the graphic file.

I wonder, do I even need the assoc array idea at all?

So, right now, I need to get myself in a case, where I can do something like
this: trace(xml.state.california[2]) and have it give me "a" back.  Assuming
0 based lists in ActionScript?  I know my trace statement above is making
you laugh, but as you know, I am hour 1 into this.

Thanks for any handholding.

_______________________________________________
[email protected]
To change your subscription options or search the archive:
http://chattyfig.figleaf.com/mailman/listinfo/flashcoders

Brought to you by Fig Leaf Software
Premier Authorized Adobe Consulting and Training
http://www.figleaf.com
http://training.figleaf.com

Reply via email to