PDA

View Full Version : Passing a reference to a view


antun
09-10-2004, 04:07 PM
You can pass a reference to a view to an instance using a constraint:


<canvas>
<view id="box" width="50" height="50" align="center" valign="middle" />

<class name="colorchangerbutton" extends="button">
<attribute name="viewtocontrol" type="expression" />
<method event="onclick">
this.viewtocontrol.setAttribute( "bgcolor", 0xff0000 );
</method>
</class>

<colorchangerbutton viewtocontrol="$once{box}">
Change color of said view to red
</colorchangerbutton>

</canvas>


You need to declare the attribute, and give it a type, "expression" - the default attribute type.

Enjoy!

aarondc
11-07-2004, 04:59 PM
I can follow this example all the way up to the call to $once(box).

I understand the $ syntax and its implications, the box reference (id of the view above), but once() doesnt make a great deal of sense to me. If I had to guess I'd say it's like DE (defer evaluate) in Coldfusion, as the argument is expecting an expression, but guessing and programming lead to unexpected results :)

I'll search the online help and see if I can determine what it does/is. As a suggestion, a quick explanation of the code (as the tutorials do), or anything "new", like this function, would round out the tips nicely.

Thanks!

aarondc
11-07-2004, 05:02 PM
(Couldnt edit my post??)

I searched All documentation and LZX reference for once and nothing showed up.

Aaron

aarondc
11-08-2004, 01:47 AM
Ok, I found it - once is a compiler directive. Not any clearer, but RTFM is going to help.

Been a while since any tips were posted; it will certainly be interesting to see the effect that going open-source has on the development and support of Laszlo. I see great opportunities and potential in this product.

antun
11-08-2004, 01:07 PM
You're right, $once{} is a compiler directive, which tells it to evaluate the contents of the attribute only once. $always{} would constrain the attribute permanently.

The constraints Developers' Guide page has lots of good information:

http://www.laszlosystems.com/lps-2.2/docs/guide/constraints.html

-Antun