This content has been marked as final. Show 11 replies
when you prefix a variable with "var" inside a function, you make that variable local to the function. ie, it doesn't exist outside the function and doesn't even exist if you exit and re-enter the function.
I understand programming fundamentals, I am aware of what goes on inside a function stays inside a function. I study in Java and PHP a lot.
Do you have any ideas about how to solve my problem. I am only creating this xml object for fun, but I don't like getting a headache when I'm enjoying myself!
Maybe I should invoke a custom class from the onLoad function and pass the Array to its constructor. Is this a good idea???
actually, i see titles is not prefixed by "var" inside jbx.onLoad. so, it will be available outside jbx.onLoad anytime after it's populated.
if trace(titles) reveals what you expect insode jbx.onLoad, and trace(titles) is undefined AFTER the onLoad method executes, you have a path error to titles.
trace() is working inside the function, outside it is UNDEFINED. If I typecast each value from the XML as a String:
titles.push( String(termArray[p].attributes.name) );
Would this solve the Path problem?
no, that wouldn't solve any path problems.
from what timeline (relative to the one that contains your posted code) are you trying to reference titles? and when (relative to the onLoad event) are you trying to reference titles?
I guess it is the root timeline. All that code is placed in the first frame of the only layer in the Flash timeline. Would the XML.onLoad() function be in a different timeline?. I'm confused by this.
Anyway I used the XML.onLoad() function as a constructor and populated a List component and a TextArea component. It works fine that way, but I would love to know why I cannot use the values retrieved from the XML object outside of the XML.onLoad() function? Do you know?
Link here to a working version & CODE ATTACHED
when (relative to the onLoad event) are you trying to reference titles?
Ah ha I think I see what you mean now or I'm more confused.
When I populate 'titles' inside the onLoad() function, it is only within that function that the XML has loaded, everywhere else in the code is instantiated prior to the XML being loaded!
Is this the Reason?
i don't know. i've been mentioning that you can't reference titles until AFTER the onLoad method executes. and i've been asking when you're trying to reference titles.
the onLoad() is executed asynchronously. code that follows the onLoad() doesn't necessarily execute after the onLoad() method.
Thanks for that, I could not get my head around how the onLoad() function worked, I understand now.
The reason I want to reference the values outside the onLoad() function is, I am trying to create a Relational 2D Array that allows me to sort the Data using a primary key.
Its just for fun, and the solution I used above lets me use the properties of a selected List Item as a primary key to access the other Arrays/Entities.
good luck and thanks again kglad!
in the onLoad() method, after parsing the xml file, i call a function that utilizes the parsed data and starts the application part that depends on the xml data.