This content has been marked as final. Show 5 replies
A better approach is to use MVC. You put your data into the model and it is accessible from anywhere (since the model is a singleton). In your case, it would be accessible by both main and your component and you wouldn't get any error.
Can you give me a example of how to change my code to that?
My previous code actually could get data too, but the problem is it get data after I need to access it. Flex seems to put in data after creation of component.
First, only do simple assignments outside of a function. Specifically, do this:
private var dataLength:Number = dataGridData.length;
inside of a function called on creationComplete.
Because of the way mxml is generated into an AS class, dataFridData does not exist when you are trying to use it
Actually, declare the var in instance scope, as yo have, just do not try to access an objects in an assignment until creationComplete is called.
I tried to access it inside creationcomplete, but i realized sometimes still happen, but sometimes fine. I think the problem is flex initiate code too fast, that the server might still not respond yet. So which cause data not send into flex client side yet. So flex cannot access that. I think I need to create a dataGridData setter function so guarantee access after data sent into flex. Anyone know how do I create a setter function?