How-To's > How do I use binding?


Use the bind keyword to create a relationship between a target variable and a bound expression. The bound expression can be a value of some basic type, an object, the outcome of a function, or the outcome of an expression.

Example Code

The following basic code creates a binding relationship between two variables:

var x = 0;  
def y = bind x;

The following code fragment shows a binding relationship between a variable and the outcome of a conditional expression:

Text {
    translateX: 8
    translateY: 20
    content: bind if (replayTimeline.running) then " Stop" else "Replay"
} 

The following code fragment shows a binding relationship between a variable and the outcome of a function:

enabled: bind enableNextButton( 
    products, 
    pageIndex, 
    productInfoView.product.index, 
    productInfoView.visible)

Tips

  • Note that variable y in the first code fragment is declared with the def keyword. This way, no code can directly assign a value to this variable, although its value can be changed by the bind operator. Using the def keyword to define variables improves performance slightly and should be preferred when it can be used.

Examples

Last Updated: April 2010
[Return to How-To's Home]