PDA

View Full Version : LzDelegate usage woes


tspratt
02-06-2004, 02:47 PM
I am trying to override an event behavior but can't seem to get LzDelegate to work. In the following very simple example, what am I doing wrong?

<canvas>
<script>
function testfunc()
{
debug.write("...---*** TESTFUNC ***---...");
}
</script>
<checkbox visible="false"/><!--required -->
<button text="clickMe!">
<method event="onClick">
var oNew = new checkbox(detail);
oNew.setAttribute("text","newcheckbox");
var lzdel = new LzDelegate( oNew, "testfunc",
oNew, "onmouseover" );
</method>
</button>
<view id="detail" x="150" />
</canvas>

antun
02-06-2004, 02:57 PM
I think you might want:


<canvas debug="true">

<method name="testfunc">
debug.write("...---*** TESTFUNC ***---...");
</method>

<checkbox visible="false"/><!--required -->
<button text="clickMe!">
<method event="onClick">
var oNew = new checkbox(detail);
oNew.setAttribute("text","newcheckbox");
var lzdel = new LzDelegate( canvas, "testfunc",
oNew, "onmouseover" );
</method>

</button>
<view id="detail" x="150" />
</canvas>



The first argument to the LzDelegate constructor function is the context. So if you want a global function, the best thing to use is a <method> in the canvas.

-Antun

tspratt
02-06-2004, 03:28 PM
Also, it is not clear in the docs, but the "args" attribute of the called method contains a reference to the calling object, which is equivalent to passing "this" as an argument from a declarative-style method call.

so:
<method name="testfunc" args="oControl">
debug.write(oControl.getAttribute("text"));
</method>
returns "newcheckbox", as expected.

Very Sweet!

Tracy

tspratt
02-06-2004, 07:19 PM
I have everything working fine with ordinary events like mouseup,down...

But onIdle is a strange animal. I want to dynamically add a delegate for onIdle, and it seems to do it but the identity of the calling control is not passed in.

In the example below, the automated format (on the dynamically instantiated control) that creates the event does not identify the control like the literal one does. What is "reference" anyway?

<canvas debug="true">
<include href="lz/checkbox.lzx"/>
<debug y="50"/>
<method name="onIdleCheck" args="oControl">
debug.write("control:" + oControl.getAttribute("text") );
</method>
<button text="clickMe!">
<method event="onClick">
var oNew = new checkbox(detail);
oNew.setAttribute("text","newcheckbox");
//var lzdel = new LzDelegate( canvas, "onIdleCheck", oNew, "onidle" );
var lzdel = new LzDelegate( canvas, "onIdleCheck", LzIdle, "onidle" );
</method>
<method event="onidle" reference="LzIdle">
canvas.onIdleCheck(this);
</method>
</button>
<view id="detail" x="150" />
</canvas>

Note in the debugger that the button onIdle displays the text but the checkbox does not.

Thanks!
Tracy

adam
02-09-2004, 10:34 AM
The event decides what data to send when the delegate is called. Many of the view events (e.g. onclick) send the sender of the event as data. The onidle sends the system time with the idle event, which can be useful for things like animation.

If you need to know which of a set of delegates called back, you need to use separate methods for those delegates to call.
new LzDelegate( this, 'meth1' , LzIdle, "onidle");
new LzDelegate( this, 'meth2' , LzIdle, "onidle");
...

<method meth1>
doIt( 1 );
....
<method meth2>
doIt( 2 );


We have a feature request against the ability for a delegate to pass more information to the callback when it executes, but no immediate plan to implement that (it's a speed tradeoff)

tspratt
02-12-2004, 04:47 PM
<canvas debug="true">
&nbsp;&nbsp; <method name="testfunc">
&nbsp;&nbsp;&nbsp;&nbsp;debug.write("...---*** TESTFUNC ***---...");
&nbsp;&nbsp;</method>

&nbsp;&nbsp;<button text="clickMe!">
&nbsp;&nbsp;&nbsp;&nbsp;<method event="onClick">
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var oNew = new LzView(detail);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;oNew.setAttribute("bgcolor",0xFFFFFF);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;oNew.setAttribute("height", "20");
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;oNew.setAttribute("width", "40");
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;var lzdel = new LzDelegate( canvas, "testfunc", oNew, "onmouseover" );
&nbsp;&nbsp;&nbsp;&nbsp;</method>

&nbsp;&nbsp;</button>
&nbsp;&nbsp;<view id="detail" x="150" width="200" height="50" bgcolor="0xE7d0D6"/>
</canvas>

I just changed the checkbox to a view, and the delegate does not work anymore.???

adam
02-16-2004, 08:21 AM
Checkbox is declared to recieve mouse events -- that is, its clickable attribute is set to true.

Usually this is done for you, so you may not know about the clickable attribute. For instance if you write <view onclick=... that view's clickable attribute will be set to true. The same is true for <view><method event="onclick">...

(in v2, at least -- in v1 it didn't, and that was the source of a lot of confusion.)

Anyway, when you new the view from script, it's not smart enough to know that it should be clickable. Changing your new statement to this:
var oNew = new LzView(detail, { clickable:true});
(or calling setAttribute( 'clickable' ,true );

should solve your problems.

tspratt
02-18-2004, 05:46 PM
Thanks!

Tracy