PDA

View Full Version : Undefined properties of dynamic fields


flexy
09-05-2006, 10:47 AM
I'm creating a load of form fields on-the-fly, and I'm getting errors in the Eclipse problems panel telling me that the properties of these fields that I am refering to are undefined. How can I 'trick' Eclipse into thinking it's fine (as it would be a runtime)??

Tink
09-05-2006, 11:29 AM
can ya post the code?

flexy
09-05-2006, 01:16 PM
Sure. Here's a summary of what I'm trying to do:


private function createFields():void
{
var label1:Label = new Label();
label1.text = "Payment:";
thisBox.addChild(label1);
var input1:TextInput = new TextInput();
input1.id = "payment;
thisBox.addChild(input1);
panel3.addChild(thisBox);
}
private function addValues():void
{
theSum = 150+Number(payment.text);
}


Currently generates an error Access of undefined property payment.

Tink
09-05-2006, 03:41 PM
the id propery in AS is not the same as the id property in MXML.

i.e. the following is the same

AS
var input1:TextInput = new TextInput();

MXML
<mx:TextInput id="input1"/>

Because you create your dynamic objects as vars within a function you can't reference them directly outside the function.

To get round this you could store a reference to your objects in an Array and then access them from there.

flexy
09-08-2006, 03:19 PM
Thanks for that. The whole object method is certainly the best way to approach it.