Name

attribute — Sets an attribute of the object that contains it.

Synopsis

LZX: attribute
Type: Class
Access: public
Topic: LZX.Basics

Description

The attribute tag has two uses:

  1. In a class definiiton, the attribute tag defines an attribute that can be set in instances of the class.

    <canvas height="30">
      <class name="mybutton" extends="button">
       
      </class>
      <mybutton text="before" myattr="after"
                onclick="setAttribute('text', this.myattr)"/>
    </canvas>
    
  2. In an instance, the attribute tag attaches an attribute to the instance. The attribute can be accessed from script.

    <canvas height="30">
    
      <class name="mybutton" extends="button">
          <attribute name="myattr" type="string" value="after"/>
      </class>
      <mybutton text="before" 
                onclick="setAttribute('text', this.myattr)">
        
      </mybutton>
    </canvas>
    

See the Developer's Guide for a complete discussion.

Also see the documentation for class and the general description of LZX attributes. The Classes tutorial describes how to use attributes to define a class.

Superclass Chain

attribute

Known Subclasses

Details

Initial Attributes (6)

Initial Attributes are given as attributes in LZX but are not generally available as properties in JavaScript.

name
<attribute name="name" type="string" />
The name of the attribute.
required
<attribute name="required" type="boolean" value=""false"" />
True if this is a required attribute.
setter
<attribute name="setter" type="script" />
Code that is executed when setAttribute is used to set the value of this attribute. This code is executed within a context in which the variable with this attribute's name is bound to the value passed to setAttribute.
type
<attribute name="type" type=""boolean" | "color" | "expression" | "number" | "size" | "string" | "text" | "html"" value=""expression"" />
The type of the attribute. This determines how the value is parsed. Attributes of type string are automatically quoted if when="immediate", for any other value of when, a literal string would have to be quoted to be used as a value.
value
<attribute name="value" type="object" />
The initial value of the attribute. The type of this value is specified by the value of the type attribute; if that attribute is not present, it's the type of this attribute in this element's tag. The attribute is given this value when the element is created.
when
<attribute name="when" type=""immediately" | "once" | "always"" value=""immediately"" />
When the initial value expression is to be evaluated. One of:
@c{immediately}
evaluate when the enclosing element is defined (must be a constant)
@c{once}
evaluate when the enclosing element is initialized
@c{always}
update whenever the value of the expression changes
The default is @c{when="immediately"}. The setting for @c{when} can be overridden when assigning a value to an attribute by using the syntax attribute name=$when value{expression}. The default for when value is @c{always}, for example: <view title="$once{computeTitle()}" /> sets the title of the view to a computed value and <view title="${parent.subtitle}" \> will cause the title of the view to track @c{parent.subtitle}.

LZX Synopsis

<class name="attribute">
</class>