|
-
[RESOLVED] What's the simpliest way to start a code execution after loading a file?
Hi, I have this problem. I try to execute a code on my Stage, the problem is when I declare my own class on which they load the file (xml) the code start in the background.
I tried to add a listener in the custom class for Event.COMPLETE but it doesn't work because it only affect the custom class, not the whole movie.
I tried something like this:
Code:
var xmlLoad: XMLLoadData = new XMLLoadData("navigation.xml");
var menuBox:MenuBox = new MenuBox();
menuBox.addEventListener("selected", handleSelect);
function handleSelect(e:Event):void {
//dosomething();
}
XMLLoadData have a constructor to load an XML file and have an event listener for COMPLETE. The problem is on Stage code, it ignored, it go to line 2 (var menuBox:...) instantly. My code work, but badly because handleSelect require the XML datas but it incapable of it because the XMLLoadData was not complete during the execution.
It like if I need to add a listener at the top level too, but I am now too confused to figure what I should do.
How I can get around this??
-
Yes, if MenuBox depends on data from the xml, then you should use a listener to respond to completion of the xml load. You can have XMLLoadData redispatch the COMPLETE event, or another event that you listen for. Something like this, which makes a few implicit changes:
Code:
var xmlLoad:XMLLoadData = new XMLLoadData();
xmlLoad.addEventListener(Event.COMPLETE, setUpMenu);
var menuBox:MenuBox;
function handleSelect(e:Event):void {
//dosomething();
}
xmlLoad.load("navigation.xml");
function setUpMenu(event:Event):void{
menuBox = new MenuBox(xmlLoad.xmlcontent);
menuBox.addEventListener("selected", handleSelect);
}
Basically, you should be aware of what depends on what else, and what happens when. It seems that you've already got some idea since you diagnosed the problem. What's left is re-arranging things so that they can all execute when you want them to.
-
Thanks for the insight, I posted my problem on another forum and with your answers and theirs I found a good solution 
Thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|