按顺序从2个urlLoader加载,并在FLEX中维护流

tkclm6bt  于 2022-09-21  发布在  Apache
关注(0)|答案(1)|浏览(108)

我有一个Flex应用程序,在creationComplete上,我调用了一个方法,在该方法中,我需要从服务器加载两个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加载程序。

但问题是,我不希望在将两个XML加载到应用程序变量之前执行SOMEGREATWORK块

因为在SOMEGREATWORK块中,我将使用它们,而在执行时,有时变量没有正确加载。

new9mtju

new9mtju1#

试试这个:

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
}

相关问题