PDA

View Full Version : 1120:Access to undefined property input_txt



kadaj
November 3rd, 2009, 02:11 PM
Hi,
I have been battling with this. I have a TextArea instance named input_txt
I add an event listener to it. and a function readInput().
Flash shows Access to undefined property input_txt 2 times.
This is by doing the OOP way. When writing in the timeline no problems are found.
I think its the problem to find the package to import.
Any idea what's causing this?

I have imported:

fl.controls.TextArea;
fl.events.*;
flash.events.*;
flash.display.*;
flash.text.*;


private function readInput(event:Event)
{
input = input_txt.text;
trace(input);
}
input_txt.addEventListener(ComponentEvent.ENTER, readInput);

Writing code using packages is really consuming a lot more time.. ah!

efos
November 3rd, 2009, 02:22 PM
Writing code using packages is really consuming a lot more time.. ah!

You'll get used to it :)

Classes get messy when you reference stage instances, It may be on the stage, but your class doesn't know that.

I believe the fix is to simply declare a 'input_txt:TextField' variable in your class. Then it will at least know what you're talking about at compile time, and at execution it will find it on the stage.

Note: Don't assign it, just declare it.

Edit: You may find that for things like TextFields it is just as easy to create them in the class; rather than place them on the stage.

kadaj
November 3rd, 2009, 02:35 PM
I believe the fix is to simply declare a 'input_txt:TextField' variable in your class.


I have done as

private var input_txt:TextArea = new fl.controls.TextArea();

The program is like:
A document class
A View class (only 2 for the time being)

In the library I have the TextArea component with export:fl.controls.TextArea

In the view class I have an Instance called input_txt and another instance called output_txt.

What I need to capture the input when i press enter after typing into the input_txt TextArea.

efos
November 3rd, 2009, 02:48 PM
I misunderstood; thought you had the text on the timeline.

Please post your whole View class; it will be easier to troubleshoot why it doesn't know what input_txt is.

kadaj
November 3rd, 2009, 02:51 PM
Leave it buddy.
I quit the OOP way.
Better to go to the old fashioned way!
Thank for taking you time to help.