Additionally, the reason you must create a function is because, as you
put it, it is something that one will use again and again. Not in the
way you understand it however.
The XML class definition knows that there is (should be) a function
called onLoad() that it must call when it successfully loads an XML
file. It doesn't exist until you write it, but the class nevertheless
expects one to exist. So, when I say that it is used again and again, I
mean that the XML class, when instantiated by any user, calls onLoad().
The reason you can't do it procedurally is because the load process is
asynchronous. When you call external_xml.load("example1.xml"), you
haven't loaded the entire file, you have merely *started* the load.
When it is finished (depending on the file size, the speed of the hard
drive, the bandwidth of the connection, etc.), then the object calls
onLoad().
I use to trip over this one, calling xml.load() then immediately trying
to use data from the load, forgetting that I needed to wait for the
onLoad() to tell me that it was done.
P.
>> -----Original Message-----
>> From: [EMAIL PROTECTED] [mailto:flashcoders-
>> [EMAIL PROTECTED] On Behalf Of Glen Pike
>> Sent: Thursday, November 09, 2006 4:51 PM
>> To: Flashcoders mailing list
>> Subject: Re: [Flashcoders] Noob, basic questions on actionscript,with
>> methodology suggestions
>>
>> Hi,
>>
>> You will need to move external_xml.load call below the onLoad
>> function because your file will probably be loaded before the handler
is
>> defined (locally).
>>
>> with trace(myXML) you have defined "myXML" inside the function -
>> this means it is not in scope outside the function. Try:
>>
>> var external_xml:XML = new XML();
>>
>> //trace if loaded, or not
>> external_xml.onLoad = function(success:Boolean) {
>> if (success) {
>> trace("xml loaded successfully.");
>> //Do something with the XML in here.
>> } else {
>> trace("xml failed to load.");
>> }
>> };
>>
>> //variable loads external XML file afterwards
>> external_xml.load("example1.xml");
>>
>> trace(external_xml);
>>
>>
>> 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
_______________________________________________
[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