View Full Version : Using the attribute tag
cmcginnis
03-03-2003, 06:45 PM
Lets say that I wanted a view to have an attribute that was actually a reference to another view, how would I do this using the attribute tags?
As an example, I would want to change the following code to use the attribute tag to specify "otherView" and not declare it in the init method.
<view name="oneView" id="oneView">
<method name="init">
super.init();
this.otherView = twoView;
</method>
</view>
<view name="twoView" id="twoView">
// laszlo stuff
</view>
Thanks!
antun
03-03-2003, 07:00 PM
Hey Chris
This should work:-
<canvas debug="true">
<view bgcolor="red">
<attribute name="test" value="Hello World" type="string" />
<view bgcolor="blue">
<attribute name="refView" init="parent" />
<button onclick="
debug.write( this.parent.getAttribute('refView').test );" />
</view>
</view>
</canvas>
I think you should be able to do <attribut type="reference" /> but that doesn't work for me.
-Antun
This code will do what you want, but note that you
cannot reference the attribute value "otherView" in the
init method of the view "oneView", it does not necessarily get initialized I guess before the attribute value gets set. But you can reference the
attribute value after the view has been initialized.
<canvas width="1000" height="800" debug="true">
<simplelayout axis="y" spacing="20"/>
<view name="oneView" id="oneView" width="100" height="50" bgcolor="red">
<attribute name="otherView" init="twoView" />
<button onclick="parent.otherView.identify()">Click Me</button>
</view>
<view name="twoView" id="twoView" width="100" height="50" bgcolor="#ccccff" >
<method name="identify">
debug.write("I am view two");
</method>
</view>
</canvas>
Right now, there's no reference type. You have two options:
1) Use the init= syntax (above)
2) Write a class that uses eval to take a reference.
The second option would look something like this:
<class
<attribute name="refname" type="string"/>
<attribute name="ref"/>
<method name="init" >
Right now, there's no reference type. You have two options:
1) Use the init= syntax (above)
2) Write a class that uses eval to take a reference.
The second option would look something like this:
<class
<attribute name="refname" type="string"/>
<attribute name="ref"/>
<method name="init" >
this.setAttribute( "ref" , eval( this.refname ));
super.init();
</method>
vBulletin® v3.8.4, Copyright ©2000-2012, Jelsoft Enterprises Ltd.