multiple HTTP Requests in for loop response handling


i working on stock market portfolio. user saves stock name , buy price ,etc .i've added details in database.but while viewing portfolio should current price of d stocks has added. while retrieving fetch data database set them in bean , each stock make http request. in result handler event set current price bean. problem entire application displayed currentprice fields null.

 

private function selectcontacts():void

{

    trace("select before");

    stmt.sqlconnection = this.isdbconnected(conn);

    stmt.text = "select * stocks_t";

    stmt.addeventlistener(sqlerrorevent.error, sqlerror);

    stmt.addeventlistener(sqlevent.result, sqlresult);

    stmt.execute();

    trace("select after");

}

 

private function sqlresult(res:sqlevent):void{

   

    httpserv = new httpservice();

    data1 = stmt.getresult().data;

    stocklist = new arraycollection();   

    for(var d:int=0;d<=data1.length-1;d++)

    {

        myportfoliobean = new myprotfoliobean();

        httpserv.url = 'http://quote.yahoo.com/d/quotes.csv?s='+data1[d].stockname+'&f=snl1a';

        httpserv.method = 'get';

        httpserv.addeventlistener(resultevent.result,ydataresult);

        httpserv.addeventlistener(faultevent.fault,ydatafault);

        httpserv.showbusycursor= true;

        httpserv.send();

       

        myportfoliobean.stocknameb = data1[d].stockname;

        myportfoliobean.buyb = data1[d].buy;

        myportfoliobean.quantityb = data1[d].quantity;

        myportfoliobean.totalquantityamountb = data1[d].totalquantityamount;

        myportfoliobean.profitb = data1[d].profit;

       

        stocklist.additem(myportfoliobean);

        }

}

public function ydataresult(evt:resultevent):void

{

    var s:string = evt.result string;

    var a:array = s.split(",");

    //to add form or individual fields

    lasttraded =  a[2].tostring();

    lasttradedfloat = parsefloat(lasttraded);

    myportfoliobean.currentb = lasttradedfloat;

    stocklist.additem(myportfoliobean);

    //stocklist.additem({current:lasttradedfloat});

}

 

the ydataresult() called after entire datagrid displayed on screen result of currentprice in datagrid column in null. eg: user has added google ,yahoo,apple( currentprice  null 3 values) after time 3 more rows (as result of call ydataresult) currentprice xx.xx displayed. want merged results.

i hope understood example, unsure it...

 

i don't see "currentprice" anywhere within code, but...

it looks using additem add new items data provider "stocklist" within both "sqlresult" , "ydataresult". if expecting merge results "ydataresult" results "sqlresult", won't work way automatically.

 

if "ydataresult" pulling in data belongs records got in "sqlresult", within "ydataresult" have search correct record created in "sqlresult", , merge data there.



More discussions in Flex (Read Only)


adobe

Comments

Popular posts from this blog

Falang and too many redirects - Joomla! Forum - community, help and support

Infinite loop detected in JErrorInfinite loop detected in JError - Joomla! Forum - community, help and support

Error 500 - Implementing reCAPTCHA with VISFORM - Joomla! Forum - community, help and support