按顺序从 2 个 urlloader 加载并在 FLEX 中保持流程

发布于 2024-10-30 19:18:39 字数 988 浏览 1 评论 0原文

我有一个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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

不乱于心 2024-11-06 19:18:39

试试这个:

    onCreationComplete = init();


private function init():void{

    //loading first XML

    urlReq = new URLRequest(PATH_FOR_XML1);
    urlLdr = new URLLoader(urlReq);
    urlLdr.addEventListener(Event.COMPLETE, doEvent);

}


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{
    //Some other operation  goes here say SOMEGREATWORK
}

Try this:

    onCreationComplete = init();


private function init():void{

    //loading first XML

    urlReq = new URLRequest(PATH_FOR_XML1);
    urlLdr = new URLLoader(urlReq);
    urlLdr.addEventListener(Event.COMPLETE, doEvent);

}


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{
    //Some other operation  goes here say SOMEGREATWORK
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文