質問

It's said that I can pass any kind of data when push a view to screen with navigator.pushView()method. I just simply pass an array like:

var arr:Array=[4,5,6,7,8,9];
navigator.pushView(SecondView,arr);

and in my SecondView constructor,no matter how I try to access it's data property,I get an ERROR :

Cannot access a property or method of a null object reference.

Am I doing it the wrong way ?

役に立ちましたか?

解決

The constructor must be called to create an instance of an object. This must be done before any properties are given values i side that object.

As such, I would always expect the data property to be null in the constructor.

Read up on the Flex Component LifeCycle. Step 1 and 2 are the important points for this problem:

  1. You call the component’s constructor...
  2. You configure the component by setting its properties...

You'll have to access the data property at some point not in the constructor. Perhaps in an event listener, such as initialize or creationComplete. Perhaps as part of a lifecycle method, such as updateDisplayList() or commitProperties().

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top