按顺序从 2 个 urlloader 加载并在 FLEX 中保持流程
我有一个Flex应用程序,在创建完成时我调用一个方法,在该方法中我需要从服务器加载两个XML文件。只有在这之后我才需要进一步继续。
目前我正在做以下
onCreationComplete = init();
private function init():void{
//loading first XML
urlReq = new URLRequest(PATH_FOR_XML1);
urlLdr = new URLLoader(urlReq);
urlLdr.addEventListener(Event.COMPLETE, doEvent);
//Some other operation goes here say SOMEGREATWORK
}
**doEvent method**
private function doEvent(evt:Event):void{
//Loading the data of XML1 to some variable which i use application wide
urlReq = new URLRequest(PATH_FOR_XML2);
urlLdr = new URLLoader(urlReq);
urlLdr.addEventListener(Event.COMPLETE, loadXML2);
}
private function loadXML2(evt:Event):void{
//Loading the data of XML2 to the some varibale which i use application Wide
}
事情我实际上在做的是,一旦一个 URL 的加载完成后,我从中加载数据,并从相同的方法开始加载第二个 URL 加载器。
但问题是 我不希望在 2 个 XML 加载到应用程序变量之前执行 SOMEGREATWORK 块,
因为在 SOMEGREATWORK 块中,我将使用它们,并且在执行时,有时变量未正确加载。
I have a flex application where on creationComplete i call a method in which i needed to load two XML files frm the server.only after which i need to proceed further..
Currently i am doing the following
onCreationComplete = init();
private function init():void{
//loading first XML
urlReq = new URLRequest(PATH_FOR_XML1);
urlLdr = new URLLoader(urlReq);
urlLdr.addEventListener(Event.COMPLETE, doEvent);
//Some other operation goes here say SOMEGREATWORK
}
**doEvent method**
private function doEvent(evt:Event):void{
//Loading the data of XML1 to some variable which i use application wide
urlReq = new URLRequest(PATH_FOR_XML2);
urlLdr = new URLLoader(urlReq);
urlLdr.addEventListener(Event.COMPLETE, loadXML2);
}
private function loadXML2(evt:Event):void{
//Loading the data of XML2 to the some varibale which i use application Wide
}
What actually i was doing is ,once the loading of one URL completed, i load data from it and the starting the loading of second URL loader from the same method.
But the problem is
i dont want SOMEGREATWORK block to be executed before the 2 XMLs are loaded to application variables
because in SOMEGREATWORK block , i will be using the them and by the time this executes, sometimes the variables are not loaded properly.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
试试这个:
Try this: