flex3 - global variable not getting set with proper values in another function in flex -
flex3 - global variable not getting set with proper values in another function in flex -
i have global variable 'csid' of string type. in code below under drawchart() function, in loop, csid variable should set '1' modellocator when i=0 , csid should set '2' modellocator when i=1.(considering lengh=2). alert in drawchart() (for csid) seems printing right 'csid' values(both 1 , 2) in datafunction() 'columnseries_labelfunc' getting csid alert value '2' , never '1'.
please find code below:
drawchart() function::
public function drawchart():void { var cs:columnseries= new columnseries(); var lenght:number=appmodellocator.getinstance().ctsmodel.productsummary.getitemat(0).collmgmtofclist.length; mychart.series = [cs]; var tempobj:object; for(csloop=0;csloop<lenght;csloop++) { cs = new columnseries(); this.csid= new string(string(appmodellocator.getinstance().ctsmodel.productsummary.getitemat(0).collmgmtofclist[csloop])); alert.show("csid="+this.csid); cs.id=this.csid; cs.displayname = 'exposure'; cs.datafunction=columnseries_labelfunc; mychart.series[csloop] = cs; }
columnseries_labelfunc() function::
private function columnseries_labelfunc(series:series, item:object, fieldname:string):object { var col:number=0; alert.show("value of csid in columnseries_labelfunc="+this.csid); if(fieldname == "yvalue" && series.id==csid){ return(item.exposureusdlist[0]); }else if(fieldname == "yvalue" && series.id==csid) { return(item.exposureusdlist[1]); }else if(fieldname == "xvalue"){ return(item.rpttype); }else homecoming null; }
please help!!!
first: assigning value global variable repeatedly within loop bad idea. nil happen that.
it's hard tell context here, reason you're having problem flow of execution follows:
drawchart() executes synchronously, counting through each step in loop, creating columnseries, each invalidated, meaning redraw on next frame. function ends, csid @ lastly value held.
the app goes next step in elastic racetrack , validates invalidated components.
columnseries_labelfunc called, csid still holding terminal value loop.
the end result beingness columnseries_labelfunc isn't called until you're finished in drawchart.
the simplest prepare read id you're setting on series in label function, rather relying on global variable @ all.
flex flex3
Comments
Post a Comment