PDA

View Full Version : Constraining to a parents attribute


jshood
11-10-2004, 10:46 AM
I am attempting to contstrain something to a parents attribute. Below is some sample code I've put together to illustrate.

The myScreen view contains an attribute called boxVisible. The "myModule" class contains a view that should be visible when it's boxVisible attribute is set to true. Becuase the myModule object can be replicated and placed an arbitrary depth away from myScreen I am attempting to contstrain the value of boxVisible, to the value I pass in.

Any thoughts are appreciated.

-Jeff

<canvas>
<class name="myModule">
<attribute name="boxVisible" type="string" />
<simplelayout axis="y" />
<edittext name="myEdit" >Some Text Could Go Here</edittext>
<text>Some More Text Goes Here</text>
<view name="myBox"
height="${parent.height}"
width="${parent.width}"
x="1"
y="1"
visible="${parent.boxVisible}"
bgcolor="red"
/>



</class>

<view name="myScreen" width="200" height="200">
<attribute name="boxVisible" type="string" value="false" />
<simplelayout axis="y"/>
<button name="btnView" text="Make Box Visible">
<method event="onclick">
this.parent.setAttribute('boxVisible',!this.parent .boxVisible);
debug.write('Box Visible is:'+parent.boxVisible);
</method>

</button>
<myModule name="boxMod" boxVisible="${this.parent.getAttribute('boxVisible')}" />
</view>
</canvas>

arina
11-15-2004, 01:31 AM
Hello,jshood!

What problem did you get?

Maybe you should try:


<canvas width="..." height="...">
<class name="myModule">
<attribute name="boxVisible" type="boolean"/>
...
<view name="myBox"
height="${parent.height-1}"
width="${parent.width-1}"
x="1"
y="1"
visible="${parent.boxVisible}"
bgcolor="red"
/>
</class>


<view name="myScreen" width="200" height="200">
<attribute name="boxVisible" value="false"/>
<simplelayout axis="y"/>
<button name="btnView" text="Make Box Visible">
<method event="onclick">
this.parent.setAttribute('boxVisible',!this.parent .boxVisible);
</method>
</button>
<myModule name="boxMod" boxVisible="${this.parent.getAttribute('boxVisible')}"/>
</view>

</canvas>

jshood
11-16-2004, 11:16 AM
Arina

Thanks for the reply. I'm still unable to get the button to work. Things work just fine if I set boxVisible = true directly on "boxMod"

However when I change boxVisible on "myScreen" the value is not passed off to "boxMod" even though the boxVisible attribute on boxMod is contrained to it's parents boxVisible attribute.

I'm wondering if I should be using delegates in a case such as this?

Any thoughts anyone.....

arina
11-17-2004, 12:10 AM
Hey, jshood!


As I understood, you want button to set visibility of your MyModule in some view. Do you want this button to be always visible or you'd like to hide all the content of the view?

regs,
Arina