I agree that chapter is required reading!  I thought the code Mark had 
written would work since views are constructed before they are 
initialized (where attribute expressions would be resolved), and I 
think, script blocks get executed as soon as they are constucted so that 
debug code isn't particularly helpful.

In fact, I've just proved that Mark's code does work.  I added 
onconstruct and oninit events:
<canvas debug="true">
        <class name="Bug">
                <attribute name="storeView" type="expression"/>
        </class>
        <view name="cuteView">
         <method event="onconstruct">
             Debug.write('onconstruct', this);
         </method>
         <method event="oninit">
             Debug.write('oninit', this);
         </method>
     </view>
        <Bug name="bugInstance" storeView="$once{parent.cuteView}">
         <method event="onconstruct">
             Debug.write('onconstruct', this);
         </method>
         <method event="oninit">
             Debug.write('oninit', this);
             Debug.write('this.storeView', this.storeView);
         </method>
     </Bug>
        
        <script>        
                Debug.write('script: ',bugInstance.storeView);
                bugInstance.storeView.setAttribute("x",2);
        </script>
</canvas>



The debugger output is:
onconstruct #cuteView
onconstruct #bugInstance
script:  null
WARNING: test2.lzx:25: call to undefined method 'setAttribute'
oninit #cuteView
oninit #bugInstance
this.storeView #cuteView

On Fri, Jun 16, 2006 at 12:56 PM, Jason Stafford wrote:

> If you add the following line to the beginning of your script, you'll 
> see that the view in question is not yet initialized:
>             Debug.write(bugInstance.isinited);
>
> Although they claim that this chapter is optional reading, I've found 
> that in my own experience I've had to read it over and over again:
> 
> http://www.openlaszlo.org/lps-latest/docs/guide/initialization-and-instantiation.html
>
> Generally I try to keep my code out of script blocks except for very 
> special cases.  It's much better to have the code as methods of views, 
> then you are much less likely to run into these sorts of problems.
>
> hope that helps.
>
> Mark Engelberg wrote:
>> I keep running into weird behavior where attributes aren't 
>> initialized
>> when I expect.  Here's an example that doesn't work, although it 
>> seems
>> like it should.  Basically, I'm storing a reference to "cuteView" in
>> the "storeView" attribute of the Bug class.  Yet, you'll see that
>> bugInstance.storeView is null at the time the script is invoked.  Can
>> someone please elucidate why this doesn't work?
>>
>> <canvas debug="true">
>>      <class name="Bug">
>>              <attribute name="storeView" type="expression"/>
>>      </class>
>>      <view name="cuteView"/>
>>      <Bug name="bugInstance" storeView="$once{parent.cuteView}"/>
>>      
>>      <script>        
>>              Debug.write(bugInstance.storeView);
>>              bugInstance.storeView.setAttribute("x",2);
>>      </script>
>> </canvas>
>> _______________________________________________
>> Laszlo-user mailing list
>> [email protected]
>> http://www.openlaszlo.org/mailman/listinfo/laszlo-user
>>
>
> -- 
> Jason Stafford
> Principal Developer
> Inspiration Software, Inc.
> The leader in visual thinking & learning
>
> Introducing INSPIRATION(r) 8, the essential tool to visualize, think, 
> organize and learn. Students use Inspiration to plan, research and 
> complete projects successfully. Learn more at www.inspiration.com.
> 503-297-3004 Extension 119
> 503-297-4676 (Fax)
> 9400 SW Beaverton-Hillsdale Highway
> Suite 300
> Beaverton, OR 97005-3300
>
> _______________________________________________
> Laszlo-user mailing list
> [email protected]
> http://www.openlaszlo.org/mailman/listinfo/laszlo-user

_______________________________________________
Laszlo-user mailing list
[email protected]
http://www.openlaszlo.org/mailman/listinfo/laszlo-user

Reply via email to