Hi,

Hopefully this isn't pilot error, but I'm seeing different behavior with event processing depending upon how the event is registered. I'm attaching an example which counts the number of times the onstart, onstop, and onrepeat events are run from an LzAnimator object. If the event handler is created using,

        <method event="onstart">
          n_onstart++;
        </method>

everything is fine. But if I create the event using,

       <method name="init">
         this.del_onstart = new LzDelegate(this, "event_onstart");
            this.del_onstart.register(a1, "onstart");
         ...
       </method>

       <method name="event_onstart">
         n_onstart++;
       </method>

all the events appear to be called too many times.

                     onstart  onstop  onrepeat
<method event="...">    2        1        1
<method name="...">     4        2        2
Expected:               1        1        1

The docs explain that onstart is called multiple times, so this explains why it is called more than expected. However, I would expect the counts to be identical for onstop and onrepeat. I ran each test with its own <view> and <animator> object.

Phil



<canvas debug="true">

<![CDATA[
  This is the output I see when I run this example:

Events created via LzDelegate:  n_onstart = 4, n_onstop = 2, n_onrepeat = 2
Events created with <method event='...'>: n_onstart = 2, n_onstop = 1, 
n_onrepeat = 1


]]>

<![CDATA[
  Events initialized with <method name="...">. I've found that doing this
  seems to generate more events than expected. This example keeps track of
  how many times onstart, onstop, and onrepeat is called.

  Don't worry if n_onstart > 1 since the docs indicate that the onstart event
  will be called multiple times. However, the docs indicate that onrepeat
  should be 1 (2 repeats) and onstop should be 1.
]]>

  <view id="view1" bgcolor="red" x="50" y="75" width="50" height="50">

    <!-- Use a timer to wait until the animator is finished -->
    <attribute name="t_start" value="0"/>
    <handler name="onidle" reference="LzIdle">
      <![CDATA[
      var now = new Date();
      if (t_start < 0)
        return;
      if (t_start == 0) {
        t_start = now.getTime();
        return;
      }

      var elapsed = now.getTime() - t_start;
      if (elapsed > 1500) {
        Debug.write ("Events created via LzDelegate:  n_onstart = " + 
a1.n_onstart + ", n_onstop = " + a1.n_onstop + ", n_onrepeat = " + 
a1.n_onrepeat);
        t_start = -1;
      } 
      ]]>
    </handler>


      <animator id="a1" attribute="x" from="50" to="100" repeat="2" 
duration="500" start="false" oninit="this.init()">

        <method name="init">
          this.del_onstart = new LzDelegate(this, "event_onstart");
          this.del_onstart.register(a1, "onstart");

          this.del_onstop = new LzDelegate(this, "event_onstop");
          this.del_onstop.register(a1, "onstop");

          this.del_onrepeat = new LzDelegate(this, "event_onrepeat");
          this.del_onrepeat.register(a1, "onrepeat");
        </method>

        <!-- Number of times each event was called -->
        <attribute name="n_onstart" value="0"/>
        <attribute name="n_onstop" value="0"/>
        <attribute name="n_onrepeat" value="0"/>

        <method name="event_onrepeat">
          n_onrepeat++;
        </method>

        <method name="event_onstart">
          n_onstart++;
        </method>

        <method name="event_onstop">
          n_onstop++;
        </method>
      </animator>

  </view>


<![CDATA[
  Events initialized with <method event="...">. The expected number of
  events are seen.
]]>

  <view id="view2" bgcolor="red" x="50" y="175" width="50" height="50">

    <!-- Use a timer to wait until the animator is finished -->
    <attribute name="t_start" value="0"/>
    <handler name="onidle" reference="LzIdle">
      <![CDATA[
      var now = new Date();
      if (t_start < 0)
        return;
      if (t_start == 0) {
        t_start = now.getTime();
        return;
      }

      var elapsed = now.getTime() - t_start;
      if (elapsed > 1500) {
        Debug.write ("Events created with <method event='...'>: n_onstart = " + 
a2.n_onstart + ", n_onstop = " + a2.n_onstop + ", n_onrepeat = " + 
a2.n_onrepeat);
        t_start = -1;
      } 
      ]]>
    </handler>


      <animator id="a2" attribute="x" from="50" to="100" repeat="2" 
duration="500" start="false" oninit="this.init()">

        <!-- Number of times each event was called -->
        <attribute name="n_onstart" value="0"/>
        <attribute name="n_onstop" value="0"/>
        <attribute name="n_onrepeat" value="0"/>

        <method event="onrepeat">
          n_onrepeat++;
        </method>

        <method event="onstart">
          n_onstart++;
        </method>

        <method event="onstop">
          n_onstop++;
        </method>
      </animator>

  </view>



<script><![CDATA[

a1.doStart();
a2.doStart();

]]>
</script>


</canvas>
_______________________________________________
Laszlo-dev mailing list
[email protected]
http://www.openlaszlo.org/mailman/listinfo/laszlo-dev

Reply via email to