var myTestObj:Test = new Test;
you can only access public objects from Test.mxml
I have this:
<mx:TextArea x="70" y="105" width="60" height="22" text="5000" id="perimeterTxt" editable="true" />
How come when I try to access this perimeterTxt.text.toString() from my actionscript, it gives me this error: TypeError: Error #1009: Cannot access a property or method of a null object reference.
This: <mx:TextArea x="70" y="105" width="60" height="22" text="5000" id="perimeterTxt" editable="true" /> is at my Test.mxml and inside I have this doTest() function which is something like this:
public function doTest():void
From my actionscript file, I try to run myTestObj.doTest(); it will return me the error of TypeError: Error #1009: Cannot access a property or method of a null object reference.
Any idea why?
Hi there, anyone know any idea about this issue?
The error occurs because you are trying to call the function before even the textarea "perimeterTxt" gets created.
Try to call this once the creation of textarea gets complete.
You need to create an instance of the component and then attach it to the display list then only you can access the Controls with in your component other wise the controls and components are not created or initialized that's why you are thrown the null object reference error.
So you need to do somethink like below:
var myTestObj:Test = new Test();
this.addChild(myTestObj); //Adds the component to DisplayList(You need to add this line of code in order to avoid the error)
If you add your component in mxml then the component will be automatically added to the display list and you dont need to add explicitly to the display list.
<comp:Test id="myTestObj" />
And now if in your actionscript you call myTestObj.doTest(); no error occurs and you can see the Alert message.