I'm trying to get my poor XML file to return node values to
an array so that I might tween them later on. My primary concert at
the moment is that I get "undefined" once attempting to trace
myArray supposedly after the function should have run. Yet, it
appears the function runs after as my output looks like
undefined (my trace(myArray))
News Item number 1 (traced values from my loop)
News Item number 2
News Item number 3
News Item number 4
My XML is simple :
<item>News Item number 1</item>
<item>News Item number 2</item>
<item>News Item number 3</item>
<item>News Item number 4</item>
Anyone have any input? I know it's a scope issue but I'm
completely fuzzy as how to figure it out.
Its not actually a scope issue. Its a timing issue. The
sequential order of the instructions in the source code is making
you think otherwise.
When you request:
Flash starts the loading process for the xml file, but
doesn't stop executing other code while its loading (which could
take an unknown amount of time, so you wouldn't really normally
want to prevent the possibility to keep doing other things).
output_xml.onLoad is called a event handler and it runs at
some point in time in the future after your xml has been loaded and
parsed by flash... the code that it executes inside its assigned
function, either directly or as calls to defined functions
elsewhere, can access the xml values because they have been loaded
and now exist.
So, in short, your line:
is executing before the xml has loaded. Which is why your
myArray value is undefined at that point in time.