As a general rule, your event handlers may be called any number of times. Event handlers should ensure that the proper pre-conditions exist before taking any action. In formal terms, event handlers must be [idempotent](http://en.wikipedia.org/wiki/Idempotence_ (computer_science)).

In this particular case, the construction of the view notices that you have a handler for `ony`, so it is called when the view gets its initial `y` value, then the scrollbar is instantiated, which causes the views layout to be recomputed, resulting in a second `ony` event.

On 2007-01-25, at 00:44 EST, Norman Klein wrote:


Why does this code generate two "ony" events ??

<canvas>

    <view name="A" width="100" height="100">
       <view name="B" width="100" height="100">
          <view name="C" width="100%">
             <handler name="ony">
                Debug.write("on y : " + A.y + A.B.y + A.B.C.y);
             </handler>
          </view>
          <scrollbar/>
       </view>
    </view>

</canvas>

Produces the following output:

on y : 000
on y : 000

I added the third view, because I initially thought that the
instantiation of a view resulted in an "ony" event being sent, but it
doesn't. Adding the axis="x" attribute to the scrollbar turns them off. So why does the scrollbar object send this event and why does it send it
twice?


Reply via email to