PDA

View Full Version : using oninit method for a view


metasarah
03-02-2003, 10:04 PM
I was experimenting with using an "oninit" method in a view. In the small lzx below, if the method is deleted, it displays the text, as expected. However, with the complete code below, the debugger will show the "init view" message two times and no text is displayed.

<canvas>
<view name="myview">
<method name="init" event="oninit">
Debug.write("init view");
</method>
<text width="parent.width" fgcolor="blue">this is some text</text>

</view>
</canvas>

Am I missing something?

Thanks,
Sarah

antun
03-02-2003, 10:47 PM
Hey Sarah

It's to do with your method name. In general you should always be wary of naming something "init" or "view" or "click" etc. etc. I think init is a very common one, because people always seem to name init methods "init".


You don't have to name methods if they're tied to an event using the event="xxx" syntax:-


<canvas>
<view name="myview">
<method event="oninit">
Debug.write("init view");
</method>
<text width="parent.width" fgcolor="blue">this is some text</text>
</view>
</canvas>


Take care,

Antun

adam
03-03-2003, 09:19 AM
Just to clarify, there are two ways to run code on init. One is to override your view's built-in init method, by naming your method "init" -- and make sure you call super.init. The other is to trigger off the "oninit" event.

The latter is the more common practice, so it's probably the better way to go.