FLEX Binding and function calls

This short example is meant to demonstrate the usage of data binging in FLEX to invoke method calls. Copy the code to an editor to be able to use the line numbers that will be specified later


<?xml version="1.0" encoding="utf-8"?>

1. we can see 2 variables. price1 and price2 and only price1 is bindable (lines 7,9)

2. we can see 2 buttons (line 30,31) that when pressed change the value of price1 and price2 (this is done in order to activate the binding)

3. line 25 we can see that when btn1 is pressed the "binding" is activated and the function "getPrice" on line 11 is called
This is done since flex calls each function that has a bindable parameter. Flex assumes that if the "IN" parameter was changed then the result of the functions may change and thus it calls the function again

4. line 25 Notice that this function is only called once even if the member "price2" is changed when "btn2" is clicked, this is so since "price2" is not marked bindable. Notice that Flex shows a warning about this in that line

5. line 27 the function getLabel is also called only once during the creation of the Label object.

6. line 28: the function "getPrices" is called due to binding only when the member price1 is changed. When the other member "price2" is changed, this function is not called , again , since price2 is not bindable

7. line 29 notice that this function is called when price1 changes due to binding, but the internal of the function is not related to the IN parameters. Actually the function can do different things and not do anything with the "in' parameters. In that case the "IN" parameters are used only for triggering the function based on the binding mechanism

8. If an assignment to a variable is done but the value of that variable was not changed then binding event will not be called

for example:

price1=0
price1 changes to 2 --> binding event is called

price1=1
price1 re-assigned the value 1 --> binding event is NOT called since no changes happened

in some cases to force binding events we use this code sample

if(price1==newPrice){
price1 = -1;
}
price1 = newPrice;