A website I'm working on (using AS2 because it's oldschool) has a larger index .swf file that loads sub-swfs using loadMovie("foo1.swf", placeToShowSwf)
. There's foo1.swf
through 4, which is silly because the only thing that's different between them is a single number in the address of an xml file that tells it what content to load. So I want to reduce this to one file, with a simple function that the index file calls to load the xml file, as seen here.
function setFooNum(i:Number) {
fooNum = i;
//my_xml = new XML(); edit: this line has since been removed and is kept for historical purposes
my_xml.load("foo"+fooNum+".xml");
};
However, for some reason, the xml file won't load. It loads properly outside the function, but that doesn't do me much good. It changes fooNum properly, but that doesn't do me any good if the wrong xml file is already loading. As far as I can tell, the code behaves as though the my_xml.load("foo"+fooNum+".xml")
isn't there at all.
Is this some sort of security measure I don't know about, and is there any way around it?
EDIT
As several people pointed out, the my_xml = new XML()
line was the culprit. Unfortunately, I'm now getting a new and exciting error. When setFooNum(i)
is called immediately after the loadMove()
in the index file, a trace(fooNum)
inside the setFooNum()
function prints that fooNum is set correctly, but a trace(fooNum)
inside the onLoad()
(which returns a success despite loading apparently nothing, btw) shows that fooNum is undefined! Also, I made a button in the index swf that calls setFooNum(3)
(for debugging purposes), which for some reason makes it work fine. So waiting a few seconds for the file to load seems to solve the problem, but that's an incredibly ugly solution.
So how do I wait until everything is completely loaded before calling setFooNum()
?