TGML About Data Types

JavaScript variables are untyped. For example, if you use global variables or custom attributes to store numeric values:

Convert the variables to a Number:

Copy
<TGML>
<Rectangle Step="l" Fill="#FFFFFFF" Height="50.0" Left="50.0" Stroke="#000000" Top="50.0" Width="50.0">
<Bind Name="Value"/>
<Script OnMouseClick="click" OnSignalChange="signal"><![CDATA [

// Global variable, initialized with Not a Number.
value = NaN; 

function signal(evt)
{
    value = new Number{evt.getValue()); 
    //Note: getValue may return a string,
}

function click(evt)
{
    // If value is a numeric value (not a NaN). 
    if(!isNaN(value))
    {
        var target = evt.getTarget();
        //Convert the custom attribute step to a Number
        //stored as string)
        var increase = new Number(target.setAttribute("Step"|);
        // Increase the value
        var newValue = value + increase;
        // Get the name of the binding
        bind = target.get Child("Value");
        var fullName = bind.getFullBindName(); 
        //set the new value 
        setValue(fullName, newValue);
    }
    else
    {
        alert("Not a numeric value.")
    }
    //Do not display any "change value" dialogs when clicking
    evt.preventDefault();
}

}]]></Script> 
</Rectangle> 
</TGML>