Thursday, November 6, 2003

Forms, Fields and Vars

Well now we are in the brave new world of Form based development in Flash, I thought it would be interesting to try a few experiments.

So I have a Form and I have a TextField, now we know TextField's can be connected to a Var and then automatically update themselves, so wouldn't it be interesting to see if I could connect a TextField to a Form class property.

So I created a setter/getter in my forms class file and connected up the TextField to the parent Forms property and ran it.

Initially it looks like nothing has happened, the TextField is blank

So lets enter some text in the TextField and see whats happens.

Wow, the setter on my Form fires, but then something really strange happens. The TextField then tries to call the getter to retrieve the updated value of the property to display in its textbox(cool!), but for some reason it can't find the getter and instead displays 'undefined' in the TextField.

After a bit more poking around I found I could resolve this problem by 'resetting' the TextFields 'Var' property after my Form has loaded, then it quite happily found both setter and getter.

A bit more poking around and I found that if I hooked the TextField Var directly to a Form member variable rather than to a property then it worked without any resetting of the Var pointer.

So there you have it, you can connect a TextField directly to a Form class file either directly to a member variable or to a getter/setter property, though the later needs to be set and initialized in the Forms onLoad method.

There might not be much use for this feature, but on the other hand...... you could have a dataProvider property on your Form and when it is set, say by new data arriving from the server, you can just update the Forms own properties with new values from the dataProvider array and your TextFields will automatically update themselves.

You could call this a poor mans databinding and it at least does indicate that somethings can be achieved without needing components, and that could be significant with MM suggesting a 125 component limit per application.


No comments:

Post a Comment