Global Variable within function
I'm having an issue with a global variable. I'm trying to give it a value within a function and it isn't working.
The variable is imageList. It's an XML List. I'm making it global so I can use it anywhere in my project. I suppose if someone has a better idea to avoid the global variable, I'm up for that too. But for now, it seems like the way to go.
Here's my .as file:
package { public class MyGlobal { public static var imageList:XMLList; } }
And here is where I'm trying to add a value to it:
function ParseImages(imageInput:XML):void{ trace ("parsing images"); MyGlobal.imageList = images.gallery.image; test_txt.text = (MyGlobal.imageList[0]);
I have import MyGlobal in the code above this and I've tried putting it in the function as well.
"text_txt.text = (MyGlobal.imageList[0]);" does work. It outputs what I want, but if I move this outside ParseImages, it gives me the error: "TypeError: Error #1009: Cannot access a property or method of a null object reference"
And here's where I want to access the new value. This is within a movieclip on the same frame as the code above:
import MyGlobal; // var l = new Loader(); l.load(new URLRequest('Photography/'+ MyGlobal.imageList[0]));
It's giving me the same same Error #1009 as above. It seems like a scope problem, but why? Shouldn't it work since it's a global variable? What am I doing wrong?
Thanks in advance for your help.