开发者

Loading from 2 urlloaders in an order and maintaining the flow in FLEX

开发者 https://www.devze.com 2023-02-22 13:22 出处:网络
I have a flex a开发者_如何学Gopplication 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..

I have a flex a开发者_如何学Gopplication 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.


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
}
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号