PDA

View Full Version : Using the text node in a custom class


antun
09-10-2003, 02:59 PM
If you've started writing your own classes, then by now you will have learned how to declare custom attributes you can set in an instance of that class. Sometimes however, it's useful to be able to use the text node (i.e. the contents of a tag) as an attribute. For example, if you were creating a custom text box, and it's far more natural to write <mytextbox>Hello, World!</mytextbox> instead of <mytextbox value="Hello, World!" />.

The ability to reference the text node of a tag was added in the LPS 1.0.1 release.


<canvas>
<class name="foo">
<attribute name="text" type="text" />
<method event="oninit">
this.bar.setText( this.text );
</method>
<text name="bar" />

</class>

<foo>&lt;abc&gt;</foo>
</canvas>


By declaring a custom attribute called "text", the view will accept a text child node, which can be accessed as though it was an attribute (.text).

Enjoy!