Hoping someone can help me out of the ninth circle of scoping hell. This
question may be basic: I've done a lot of actionscript-related reading, not
so much practical coding.
I'm using xfactorstudio's Xpath implementation to parse XML and to attempt
to return an array:
myDoc = new XML();
...
myDoc.onLoad = function(success){
arNodes = XPath.selectNodes(this,"/rss/channel/item/media:content/@url");
}
}
This works.If I attempt to loop through the array as with the code below, I
will get a collection of results:
myDoc = new XML();
myDoc.onLoad = function(success){
arNodes = XPath.selectNodes(this,"/rss/channel/item/media:content/@url");
for (var i = 0; i < arNodes.length; i++) {
trace("Element " + i + ": " + arNodes[i]);
}
}
If I attempt the same loop outside of the function body that's attached to
myDoc.onLoad, I return nothing. My array "arNodes" dies outside of the scope
of the inline function. I've tried various things to put the array on
timeline or global scope; these do not work. I've attempted to add a return
parameter, but there's a basic problem. That basic problem is that normal
attempts to cast a variable based on the output of a function are at odds
with executing the function with the success of myDoc.onLoad.
I am missing something basic, and it's driving me nuts. Perhaps I need to be
thinking about setting up a listener attached to onLoad, and executing
functions when the listener fires. At this point my brain is too knotted to
know heads from tails on this problem. Can someone show me the light?
Thanks,
-KF