- 浏览: 489214 次
- 性别:
- 来自: 深圳
文章分类
- 全部博客 (185)
- job (15)
- linux/windows/unix/bash/shell (31)
- JAVA/J2EE/spring/hibernate/struts (30)
- VC/C++ (48)
- mysql/postgresql (6)
- php/jsp/asp/pear (1)
- FMS/flex/openlaszlo/red5/openmeetings (34)
- apache/tomcat/ftp/svn (6)
- xen/vm/Hadoop/cloudcompute (6)
- visual studio/eclipse/zendstudi/ant (8)
- others (1)
- windows异常处理 __try __except (1)
- (1)
- matlab (4)
- android (0)
最新评论
-
hongzhounlfd:
很透彻,很详细
依赖注入和控制反转 -
jefferyqjy:
谢谢~言简意赅~很明了!
依赖注入和控制反转 -
elderbrother:
太好了,谢谢
依赖注入和控制反转 -
east_zyd_zhao:
终于搞明白了
依赖注入和控制反转 -
Dremeng:
完美,一看就懂理解透彻
依赖注入和控制反转
Combining Tags and Script in LZX Programs (openlaszlo)
As mentioned earlier, virtually all nontrivial LZX programs contain both (XML) tags and script. Tags are used declaratively, that is, to define objects and their attributes. Script is used procedurally, that is, to explicitly define a series of steps. Although the two kinds of code are liberally intermixed within LZX — for example, script can appear within tags — each syntax locally maintains its integrity.
So for example, within declarative LZX code, comments are denoted
<!-- XML comment -->
while within JavaScript, comments are denoted
// JavaScript comment
Thus LZX is similar to an alloy of two metals that do not chemically combine.
Because the declarative and procedural portions of a program can be so intertwined, it can be a little tricky, at first, to recognize them within a program. However, once you gain a little experience and begin to grasp the underlying logic of LZX you will find that you hardly notice the alternating syntaxes. The following paragraphs explain how and why to employ the two "flavors" of LZX. Consult the documentation for your IDE or text editor to learn how to use the LZX DTD or schema to give visual cues that indicate what portions of the program are in each syntax.
The preferred normalized form of class names is lz.[tagname]
where [tagname] is the name of a tag. So for example a if you created a class called "bob":
<class name="bob"/>
then from the point of view of JavaScript, this would be an lz.bob object.
In earlier versions of LZX (before OpenLaszlo 4), there was an asymmetric mapping between tag and class names, often of the form LzFoo <—> <foo>, as in the correspondence between, say the class name lz.view
and the tag name <view>
. (Notice in lz.view the mixed case, and the absence of the period between lz and the tag name.) Also there was a distinction between LFC classes and user-created classes. The new lz.foo form is consistent across LFC classes and user-created classes. The old forms will still work, and they appear throughout this documentation and in example code. At some point, however, the old forms will probably be deprecated, and it would be a good practice to adopt the new form in your code.
Let's start by making a distinction between what is syntactically allowable and what is meaningful.
Remember that all LZX programs are well-formed XML files. That means that all portions of the program, including embedded JavaScript, must conform to XML rules. Therefore where JavaScript uses characters that are meaningful to XML, such as the left angle bracket <, you must make sure that those characters don't confuse the XML parser. You can do that in either of two ways:
This is the sum total of rules for making sure that XML does not trip on JavaScript.
Although the admixture of two different sets of language rules in one language does create opportunities for confusion, it's fairly easy to recognize how LZX programs are structured, and what kind of code goes where. There are only a few contexts in which script code can appear in LZX programs. After you learn to recognize these contexts you are unlikely to be confused about what syntax applies. JavaScript is used:
-
between an opening and closing
<script>
and</script>
tag; -
between an opening and closing
<method>
and</method>
tag; -
between an opening and closing
<handler>
and</handler>
tag; -
with the double-quoted right hand value of an assignment statement within certain tags, such as
oninit="
.script expression
"
As we said earlier, most things that you can do in LZX can be done either with XML tags or JavaScript APIs, and mastering LZX requires developing a subtle understanding of how and when to use each. You will find, in general, that tags are best for computations that can be done at compile-time — such as laying out the canvas — and script is best for run-time things, such as responding to user input. But in order for you to make any use of that information you need to understand what is done at compile time and what is done at run time, and much of that is under your control, and dependent on the problem you're trying to solve.
In other words, there is no simple set of unambiguous rules that tell you when to use tags versus when to use script. But there are, however, design patterns common to all well-made LZX programs.
Remember, LZX is primarily a language for manipulating visual objects called views. So the question of when to use tags versus script is usually asked in the context of the creation of views and manipulation of their attributes. Script can be used for other things, such as global functions, but in those instances the need to write procedural code (i.e., script) is usually clear-cut. The finesse part has to do with manipulating views and their attributes.
For example, a simple two-word constraint might express a relationship between views that would require thirty lines of code to express. Most of the time the constraint is the better programming solution. But not always.
Although there are no absolutes, there are some general principles that define best practice in LZX development:
-
Use tags when that is the only option.
-
Use JavaScript when that is the only option.
-
If something can be done with either tags or script, use tags (unless there is a good reason not to).
Each of these principles is described briefly below.
There are certain tags that perform functions that cannot be done using script. For example, the root node (and enclosing tag) of every LZX program is <canvas>
. Every LZX program begins with <canvas>
and ends with </canvas>
; there is no alternative structure using script. Similarly there are no script equivalents for <splash>
, <method>
, <attribute>
, <resource>
, <font>
, and several other tags. Moreover, within certain tag definitions there are certain attributes that can only be set in the tag.
There are several JavaScript APIs that perform functions that cannot be done using tags. For example, LzDelegate, lz.event, LzParam
and similar APIs perform operations that cannot be done using tags. Similarly, there are certain attributes of objects that can only be referenced by script, even for objects that were created with tags. For example, consider
<view name="franklin">
There is an attribute, franklin.subviews,
that can be accessed by script; it is not possible to set or access that attribute in a tag.
In the large number of cases where it is possible to do something using either tags or views, it is generally better to use tags. For example you can create a new view called "sam" using tags
<view name="sam">
or script
sam = new lz.view();
When you use the tag syntax you can quite naturally create hierarchies of nested subviews, define attributes as constraints, and lay out your code in a way that helps you conceptualize the placement of views on the canvas. Achieving any of these results in pure JavaScript would be a colossal pain and negate much of the benefit of the language. Learning to think in LZX means learning to think in terms of views that act nearly autonomously according to the constraints you establish at their creation.
Sometimes it's better to write procedural code instead of declarative code. This may become necessary, for example, to achieve optimal performance: multiply-constrained systems can sometimes become CPU bound. Other times procedural code may make your program's behavior easier to understand: complex rule-based view systems sometimes become inscrutable.
发表评论
-
Red5安装和配置
2011-02-24 10:23 4013Red5安装和配置参考网页:http://www.cahblo ... -
基于Moodle平台的网站调查报告
2011-02-24 10:18 2533基于Moodle平台的网站调查报告 网站举例: ² 西南 ... -
moodle插件模块功能汇总
2011-02-24 10:03 4946Moodle官方提供654种插件或者模块moodle.org ... -
moodle 一体包安装手册(window)
2011-02-24 09:55 1252见附件 -
moodle中上传文件大小控制
2011-02-24 09:51 1804第一步:修改在php4下POST文件大小的限制1.编修php. ... -
linux下面安装moodle
2011-02-24 09:50 20531. 安装moodle运行 ... -
OpenMeetings安装文档
2011-02-15 11:09 2569OpenMeetings 是一个多语言可定制的视频会议和协作系 ... -
Compilation and Execution (openlaszlo)
2010-11-22 11:02 10227. Compilation and Exe ... -
Data Access, Manipulation, and Binding (openlaszlo)
2010-11-22 10:33 11615. Data Access, Manipu ... -
Constraints(openlaszlo)
2010-11-22 10:18 1095constraint 表示可变的变量赋值形式 In LZX, ... -
Events and Methods (openlaszlo)
2010-11-22 09:35 13373. Events,Methods ,han ... -
Dimdim&Moodle安装配置文档节选
2010-11-09 17:40 2514Dimdim&Moodle安装配置文档节选 ... -
Red5如何响应rmpt的请求,中间涉及哪些关键类?
2010-11-01 15:35 1507Red5如何响应rmpt的请求,中间涉及哪些关键类? 响应请 ... -
red5的eclipse插件和用法
2010-10-30 20:56 1105参见http://www.red5.org/wiki/Red5 ... -
red5集群分析
2010-10-28 19:42 49901. 边(Edge ): 1. 边的主要作用是管理连接,并可以 ... -
red5源代码分析
2010-10-26 08:59 3827Red5如何响应rmpt的请求 ... -
创建第一个red5程序
2010-10-25 15:33 21111.下载最新版本的RED5 http://osflash.or ... -
openlaszlo中多媒体组件介绍
2010-10-14 15:50 1095在openlaszlo中我们可以处理图像,音视频等媒体文件。详 ... -
openlaszlo组件的简单介绍
2010-10-14 15:50 1258openlaszlo组件的简单介绍 收藏 在写laszlo ... -
创建一个简单的openlaszlo程序
2010-10-14 15:49 1030前面说到过openlaszlo程序是一组xml格式和javas ...
相关推荐
changes in the variance behavior, and a fourth examines variance changes over multiple timescales. We evaluate and compare all of these methods using ROC curves that illustrate the full tradeoff ...
2018-xDeepFM- Combining Explicit and Implicit Feature Interactions for Recommender Systems
关于Combining active learning and semi-supervised learning to construct SVM classifier的文章
Combining text and link analysis for focused crawling—An application for vertical search engines.pdf
Combining Correlation and Interference Methods
L. Kuncheva 2004 年的 Combining Pattern Classifiers Methods and Algorithms
visual
With this book, a stellar author team covers the new controls in the AJAX toolbox, the back button history, and script combining, and they also examine the new capabilities of WCF including changes ...
Lucas/Kanade Meets Horn/Schunck: Combining Local and Global Optic Flow Methods Lucas/Kanade 与 Horn/Schunck: 局部与全局光流方法的结合
presents a method that combines shadow detection and a 3D box model including shadow simulation, for estimation of size and position of vehicles.
By uniquely combining current concepts and practical applications in computer graphics, four well-known authors provide here the most comprehensive, authoritative, and up-to-date coverage of the ...
结合EfficientNet和视觉变换器进行视频假检测_Combining EfficientNet and Vision Transformers for Video Deepfake Detection.pdf
Sabourdy, combining various implicit surfaces with soft blending capacities in a CSG tree. This extension allows integration of plane surfaces, skeletons and many other types of implicit surfaces. It ...
3,how to use matlab functions in c++ through comtool and other means, such as matcom.4,the api reference for matlab.you might find this document in matlab help directory. hoWEVER,it's useful to put it...
Combining RGB and depth features for action recognition based on sparse representation
of spurious solutions by combining basic and readily available information about the connectivity of the process with the results from causal measurement-based analysis. Connectivity information is ...
Combining supervised and unsupervised learning for automatic attack signature generation system
Combining 3D Morphable Models: A Large scale Face-and-Head Model
Combining Design Thinking and Software Requirements Engineering to create Human-centered Software-intensive Systems_结合设计思维和软件需求工程,创建以人为本的软件密集型系统.pdf
Investing and Pricing with Supply Uncertainty in Electricity Market: A General View Combining Wholesale and Retail Market