
XML.parentNode Property
This is the Title of the Book, eMatter Edition
Copyright © 2007 O’Reilly & Associates, Inc. All rights reserved.
940
|
ActionScript Language Reference
We rely on onLoad() events to tell us when it’s safe to process xmlDoc.IfonLoad() is trig-
gered, we know that the loading and parsing of external XML data have completed, so we
can safely access that loaded content. Hence, the onLoad() handle alleviates the need to
write preloading code to wait for data to arrive after the invocation of an XML load() func-
tion. For example, in the following code we load an XML document and then wait for our
custom handleLoad() function to execute automatically when loading completes. If loading
was successful, we process our XML content with the displayProduct() function. Other-
wise, we show an error message by executing the displayError() function. (The
displayProduct() and displayError() functions are custom functions that we’ve written to
display information to the user, but they are not shown here.) Here is the code:
myDoc = new XML();
myDoc.onLoad = handleLoad;
myDoc.load("productInfo.xml");
function handleLoad(success) {
if (success) {
output = "Product information received";
displayProduct(); // Call custom display function
} else {
output = "Attempt to load XML data failed";
displayError(); // Call custom error display function
}
}
Notice that we assign our onLoad() callback before ...