antun
06-24-2003, 02:41 PM
If you've been using the LPS since before v1 was released, you may be familiar with the verbose way of declaring attributes using the <attribute> tag. This is frequently used for custom constraint types, setting attribute values at init time and so forth, in addition to defining custom attributes in class definitions.
The v1 release provides more powerful and user-friendly syntax for accomplishing some of this:
<text name="foo" label="${'My x position is ' + this.x}" />
You can put any JavaScript expression in between the curly braces, and it will be evaluated. The syntax above also constrains the attribute to the expression, so if you move the text field (try using the debugger for this) the text field will be updated.
Writing ${} is short for $always{} - the "always" referring to the constraint nature of the attribute. Alternatively, if you needed an attribute to be evaluated once, you can use the $once{} syntax:
<view name="foo" width="200" height="30" bgcolor="red">
<view width="$once{parent.width/2}" height="30" bgcolor="blue" />
</view>
In this case, if foo's width is changed (again, try using the debugger here), the blue view's width will remain constant. This is a replacement for the old syntax:
<attribute name="width" init="parent.width/2" type="number" />
This does not mean that the attribute tag is now useless - it is still required for defining custom attributes in class definitions, as well as verbosely declaring attributes for code clarity. In a class definition, you can now use the when attribute of the attribute tag, to correspond with the above described behaviour:
<class name="myClass">
<attribute name="myInitOffset" value="this.x" type="number"
when="once" />
<attribute name="halfMyWidth" value="this.width/2"
type="number" when="always" />
</class>
Enjoy!
The v1 release provides more powerful and user-friendly syntax for accomplishing some of this:
<text name="foo" label="${'My x position is ' + this.x}" />
You can put any JavaScript expression in between the curly braces, and it will be evaluated. The syntax above also constrains the attribute to the expression, so if you move the text field (try using the debugger for this) the text field will be updated.
Writing ${} is short for $always{} - the "always" referring to the constraint nature of the attribute. Alternatively, if you needed an attribute to be evaluated once, you can use the $once{} syntax:
<view name="foo" width="200" height="30" bgcolor="red">
<view width="$once{parent.width/2}" height="30" bgcolor="blue" />
</view>
In this case, if foo's width is changed (again, try using the debugger here), the blue view's width will remain constant. This is a replacement for the old syntax:
<attribute name="width" init="parent.width/2" type="number" />
This does not mean that the attribute tag is now useless - it is still required for defining custom attributes in class definitions, as well as verbosely declaring attributes for code clarity. In a class definition, you can now use the when attribute of the attribute tag, to correspond with the above described behaviour:
<class name="myClass">
<attribute name="myInitOffset" value="this.x" type="number"
when="once" />
<attribute name="halfMyWidth" value="this.width/2"
type="number" when="always" />
</class>
Enjoy!