0

I have an array collection object 'invArrayCol' which holds some data. I also have a datagrid. I have set dataProvider as invArrayCol.I displays the data properly when i use it with data grid. But the same invArrayCol shows null when used anywhere other than datagrid. I wrote this code

protected function titlewindow1_creationCompleteHandler(event:FlexEvent):void
{
    Cgt=new CgtSRObject();

    var autoobj:CSAutoNumberType=new CSAutoNumberType();
    autoobj.addEventListener(ResultEvent.RESULT,getInvNubmer);
    autoobj.getInvNo(invoiceType);

    trace(robj.salesPerson_Id);     

    getSalesReturnCgt.token=csInvoicePrint.getCgtData(robj.receive_Id);
    getSalesReturnCgt.addEventListener(ResultEvent.RESULT,getInvArrList);
    trace(Cgt.sr_no);

    datagrid_dataprovider=new ArrayCollection();
    datagrid_dataprovider=invArrayCol;
    calculateTotal();
}

This 2 lines set data to invArrayCol

getSalesReturnCgt.token=csInvoicePrint.getCgtData(robj.receive_Id);
getSalesReturnCgt.addEventListener(ResultEvent.RESULT,getInvArrList);

But here it gives value of invArrayCol as null.

datagrid_dataprovider=new ArrayCollection();
datagrid_dataprovider=invArrayCol;

Please tell me some way out of this.

1
  • You say that the variable invArrayCol is null. But in the code you have shown, this variable is never assigned a value (so it's going to be null). The code snippets you have shown are not sufficient to diagnose the problem. Also, why do you set the data grid's dataProvider twice? The first time to a new ArrayCollection, then the second time toinvArrayCol? Commented Jun 1, 2012 at 6:52

1 Answer 1

1

The ResultEvent's result may return an ObjectProxy, in case the data is of length 1. Casting via 'as' would lead to a silent failing of the cast. So simply checking the type of the result would let you determine if the result can be used directly or if you have to wrap an ArrayCollection around it.

// This happens asynchronously, should have no effect in the function
getSalesReturnCgt.addEventListener(ResultEvent.RESULT,getInvArrList);

Also, the

// datagrid_dataprovider=new ArrayCollection(); // This line is obsoloete
datagrid_dataprovider=invArrayCol; // invArrayCol will get its value later

So, it looks like your expectation is for some code to have it executed synchronously, but it is always working asynchronously.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.