View Full Version : attributes
kentyler
11-21-2003, 06:12 PM
is it possible to add and use a new attribute with a tag, like the "text" tag, without subclassing it, just including the new attribute when you use the tag ?
kentyler
11-21-2003, 06:57 PM
I guess I answered my own question. Can't.
antun
11-22-2003, 04:32 PM
Yes, if you mean:
<view>
<attribute name="txt" type="string" value="foo" />
</view>
... then you can refer to that attribute in script.
-Antun
whisperstorm
11-22-2003, 05:00 PM
Looking at XBL -- is there a way to create a new attribute and "behind the scenes" have that attribute behave like one that already exists. For instance say I had a tag like "chesspiece" and this tag inherited from "view" but instead of having an attribute "x" that determined the horizontal position of the chesspiece tag, I wanted to call it "offset" or something. But I want "offset" to "behave" like "x" in every way --- via javascript, tag syntax, etc.
antun
11-23-2003, 07:20 AM
This should work:
<canvas debug="true">
<class name="chesspiece" bgcolor="red" y="20" x="${this.offset}"
width="20" height="20">
<attribute name="offset" type="number" value="0" />
</class>
<chesspiece name="foo" />
</canvas>
-Antun
whisperstorm
11-23-2003, 08:50 PM
Oh yeah! Duh, this is something described even in the 10 min laszlo tutorial... hmmm.
stephan
11-24-2003, 03:11 PM
<view>
<attribute name="txt" type="string" value="foo" />
</view>
I'm confused, isn't this suppose to be value="'foo'" ?
antun
11-24-2003, 03:15 PM
Well noticed. The answer is no, because I specified that the attribute type was string:
<view>
<attribute name="txt" type="string" value="foo" />
</view>
If I had omitted the "type" attribute, I could have double-quoted the value attribute, using the syntax you suggested:
<view>
<attribute name="txt" value="'foo'" />
</view>
-Antun
I'm confused, isn't this suppose to be value="'foo'" ?
stephan
11-24-2003, 09:06 PM
Thanks, this is good to know.
whisperstorm
11-24-2003, 11:24 PM
It'd be great to hear more tips about classes and attributes. I had a kinda of "a-hah" moment in coding lzx recently when I realized that building up classes w/attributes etc. is an interesting "new" way to build an app for me.
antun
11-25-2003, 09:13 AM
I'll definitely endeavor to write some tips on classes and attributes in that case.
But you should know that building apps with classes is the way to build Laszlo apps. If you haven't done so already, have a look at apps like Blueprint, Dashboard and Calendar:
Most of them are comprised of a bunch of files that define classes, many of which are instantiated in a main file (typically named after the app - e.g. calendar.lzx).
The way I scan app source code is to just search for "<class" in the files, and look at all the classes. If you're a UNIX person you might just do something like: grep '<class' *.lzx, which gives you a quick listing of the building blocks of the app:
basepanel.lzx: <class name="basepanel" height="100" width="100">
cal-button.lzx: <class name="calButton" clickable="true" >
day.lzx: <class name="calendar_day" bgcolor="#7A949E"
dayname.lzx: <class name="dayname" width="63"
event.lzx: <class name="calendar_event"
eventselector.lzx: <class name="eventSelectorbar" clip="true"
eventselector.lzx: <class name="ibutton" clickable="true">
gridsliderlayout.lzx:<class name="gridsliderlayout" extends="layout" >
infopanel.lzx: <class name="infoTab" extends="basetabelement" clickable="false" bgcolor="0xEEF0EB" >
infopanel.lzx: <class name="textbox" height="14">
infopanel.lzx: <class name="inputtextbox" extends="inputtext" bgcolor="white"
infopanel.lzx: <class name="info_Panel" extends="basepanel" clip="true">
selected-daylook.lzx: <class name="selectedDayLook">
simpletimelayout.lzx:<class name="simpletimelayout" extends="layout" >
vscrollbar.lzx:<class name="basevscrollbar">
vscrollbar.lzx:<class name="vscrollbar" extends="basevscrollbar">
-Antun
whisperstorm
11-25-2003, 05:57 PM
yes, I think I've sorta stumbled upon this. It really speaks well of your design that this happens. I think the biggest leap was to realize that as soon as I defined a class "foo" that I could now use "foo" as a tag <foo>. That's quite different than say HTML or even XUL.
I'm going to use this idea for my Skipper 2D game library... where instead of a ton of views, I'll allow the developer to have high level objects like "ship" or "platform" or "bullet". Great fun!
antun
11-26-2003, 08:41 AM
If you explore the class system in LZX, you'll find it's pretty complete. You can define your own classes, and then instantiate them. You can extend them and overwrite methods and attributes in instances, and so forth.
To use one of your suggestions, you could write a ship class, that was able to moveForward(), moveBackward(), turnLeft(), sink() and so forth. Then you could write another class, cruiser, and in that set the moveDistance attribute that the moveForward() and moveBackward() methods inherently used. Since a cruiser is a warship, it would also have a fire() method, whereas the regular ship class did not. Then you might write a battleship class (that extended cruiser), with a greater firingRange and moveDistance attributes.
You might also create an instance of your battleship class, named Hood, and in that instance overwrite say, the tonnage attribute, or a method (say you might change the internals of the fire() method).
The nice thing about playing with object oriented concepts in Laszlo is that you can literally see them.
Take care,
Antun
antun
11-26-2003, 09:34 AM
Thought you might want to know, this week's Tip is about attributes:
http://www.laszlosystems.com/developers/community/forums/showthread.php?s=&threadid=517
-Antun
Originally posted by whisperstorm
It'd be great to hear more tips about classes and attributes. I had a kinda of "a-hah" moment in coding lzx recently when I realized that building up classes w/attributes etc. is an interesting "new" way to build an app for me.
vBulletin® v3.8.4, Copyright ©2000-2012, Jelsoft Enterprises Ltd.