The website I'm working on (using AS2 because it's oldschool) has a higher index .swf file, which loads sub-swf using loadMovie("foo1.swf", placeToShowSwf) . There foo1.swf through 4, which is stupid, because the only thing that differs from them is a single number in the xml address of the file, which tells it which content to load. So I want to reduce this to a single file with a simple function that the index file calls to load the xml file, as shown 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 is not loading. It loads correctly outside the function, but that does not do me much good. It changes fooNum correctly, but it does not do me any good if the wrong xml file is already loading. As far as I can tell, the code behaves as if my_xml.load("foo"+fooNum+".xml") does not exist at all.
Is this some kind of security measure that I don't know about, and is there any way out there?
EDIT As pointed out by several people, the culprit was the line my_xml = new XML() . Unfortunately, now I get a new and exciting bug. When setFooNum(i) is called immediately after loadMove() in the index file, trace(fooNum) inside the setFooNum() function prints that fooNum is set correctly, but trace(fooNum) inside onLoad() (which returns success despite loading apparently nothing, btw) shows that fooNum is undefined! In addition, I made a button in the swf index that calls setFooNum(3) (for debugging purposes), which for some reason makes it work fine. So waiting a few seconds for the file to download seems to solve the problem, but it is an incredibly ugly solution.
So, how to wait until everything is fully loaded before calling setFooNum() ?
source share