`

Events and Methods (openlaszlo)

阅读更多

3. Events,Methods ,handlers

 

3.1. Events

event是建立在对象之间通信的机制。比如当鼠标点击的时候,从服务器接受数据的时候,或者当view建立的时候。Events are the mechanism by which objects communicate with each other when something changes. For example, an event might be generated when a mouse button is clicked, or when data arrives from a server, or when a view has been constructed.

在LZX中,events不是广播,是使用delegates的点对点的通信。当事件发生的时候这些点是基本的功能点。

In LZX programs, events are not broadcast, but rather they are communicated in a point-to-point fashion using delegates, which are basically function pointers that are referenced when events happen.

这种措施增加了灵活性和减少了使用events的负担。

This implementation increases flexibility and reduces the overhead of using events. However, for the purposes of the discussion in this chapter we're going to ignore delegates and speak of events in a slightly less 严密的方式, saying, for example when such-and-such an event occurs, thus and such happens, leaving aside for now an explanation of how it happens.

Views have 大约two dozen defined events, as listed on the entry for <view> in the LZX Reference Manual. Many of these events that deal with user input, such as onblur, onclick, onkeydown, will be familiar to JavaScript programmers. Other events, such as onheight and onopacity, pertain to views' visible attributes. Finally, the oninit and onconstruct events are related to the creation of the instances of view objects. Similarly, other system-defined LZX objects such as Datasets (see below) have events associated with them.

Events and attributes often 成对出现, and in fact, the default behavior of the setAttribute() method is to set the named property and send the event called "on" + property. For instance, when a view changes its x (horizontal) position, it sends the event onx with the new value for its x property. This means that in addition to system-defined events, there exists an event for each attribute you define.

When an event happens, control is transferred to its associated event-handler (if one is defined). Events can be sent with a single argument, which usually conveys information about the property that changed.

Elsewhere in this Guide we discuss how events are implemented in LZX, and how the event architecture bears upon program design. In particular, Chapter 30, Delegates discusses the relationship between events and delegates.

 

3.2. Methods    //定义javascript函数

In LZX, a method is a JavaScript function associated with a particular object.

Functions are invoked using the () operator. Thus,

<view name="dog">   
  <method name="bark"> 
    <!-- some JavaScript code --> 
  </method> 
</view>

Defines a function that is executed when invoked by name, as in

dog.bark();

In JavaScript, the this keyword is used to refer to the object through which the function was invoked.

 

3.3. Handlers

A handler is like a method. But whereas a method is invoked by its name, a handler must be associated with a particular event. The handler script will be executed when the referenced view receives an event with this name. For example,

<view> 
  <handler name="onclick"> 
    <!-- some JavaScript code --> 
  </handler> 
</view>

defines a function that is executed when the view is clicked on. Consider

 
<view> 
  <method name="bark"> 
    <!-- some JavaScript code --> 
  </method> 
  <handler name="onclick"> 
    this.bark()  
  </handler > 
</view>

When the view is clicked on, the onclick event causes the execution of the handler() which in turn invokes the method named bark(). Event handlers are often identified in an opening tag, as in

<view onclick="clickHandler()"> 
  <method name="clickHandler"> 
    <!-- some JavaScript code --> 
  </method> 
</view> 

There are three general categories of methods and handler:

  • "On init" methods that are invoked when their parent object is created;

  • handlers that are invoked when their parent object receives a specified event;

  • named methods that are explicitly invoked by other methods.

Note that you can define a method using conventional JavaScript syntax, but in LZX the preferred way to declare a method is with the <method> tag.

Also note that in LZX, unlike many other object-oriented systems, you can override a method in an instance of an object. This topic is covered in Chapter 33, Extending Classes.

 

分享到:
评论

相关推荐

    OpenLaszlo-SAMSIG-05.ppt

    - **事件(Events)**:处理用户输入和其他触发条件下的响应行为。 - **脚本(Scripting)**:提供脚本语言支持,用于控制应用程序的行为。 - **内联 HTTP(Inline HTTP)**:允许应用程序直接进行网络请求。 - **绘图 API...

    openlaszlo本地帮助文档

    手册中的"labs.openlaszlo.org"可能是一个指向OpenLaszlo官方实验室的链接,这个实验室通常包含各种示例、实验项目和最新的技术探索,是学习和了解OpenLaszlo最新功能的好地方。在这里,开发者可以找到实际的代码...

    Applet & Openlaszlo

    Applet和Openlaszlo是两个在Web开发领域中用于创建动态、交互式用户体验的技术。本文将深入探讨这两个概念以及它们之间的通信机制。 首先,Applet是Java编程语言的一个组成部分,它允许开发者创建可以在Web浏览器中...

    OpenLaszlo —— 一个快速构建和部署富 Internet 应用程序的平台

    OpenLaszlo —— 一个快速构建和部署富 Internet 应用程序的平台 -- Linux,C,C++,Java,Ajax,XML,perl,php,python,ruby,MySQL,Gnome,KDE,Qt,Gtk,bash,shell,嵌入式,网络,信息安全,操作系统,数据结构,编译原理

    openlaszlo-4.9.0-windows-dev-install.part2.rar

    openlaszlo应用程序开发使用的是基于XML的LZX语言,它可以被编译成DHMTL,SWF等格式。 openlaszlo可作为openmeetings客户端的编译。 因安装程序90+MB,所以切分为两个压缩包。 openlaszlo-4.9.0-windows-dev-install....

    openlaszlo-4.9.0-windows-dev-install.part1.rar

    openlaszlo应用程序开发使用的是基于XML的LZX语言,它可以被编译成DHMTL,SWF等格式。 openlaszlo可作为openmeetings客户端的编译。 因安装程序90+MB,所以切分为两个压缩包。 openlaszlo-4.9.0-windows-dev-install....

    openlaszlo-4.7.3-windows-dev-install (1).exe

    openlaszlo应用程序开发使用的是基于XML的LZX语言,它可以被编译成DHMTL,SWF等格式。 是openmeetings视频会议系统的默认开发编译工具。

    openlaszlo计算器

    这是用Openlaszlo开发的计算器程序,可以实现基本的计算操作。 我是刚学openlaszlo,欢迎朋友们提出宝贵意见!

    论文研究-使用OpenLaszlo构建J2EE中的RIA程序 .pdf

    使用OpenLaszlo构建J2EE中的RIA程序,高春阳,龚群侃,当前,Web 应用程序就要进入了一个新的时期,富互联网客户端(RIA ,Rich Internet Application) 以其极大地用户交互性、优秀的外观设计、良好��

    Laszlo技术手册续

    2. **配置步骤**:首先,下载OpenLaszlo Server的servlet文件(如openlaszlo-3.3.3-servlet.war),将其解压并放入Tomcat的webapps目录下。启动Tomcat后,LPS会被自动部署。接着,可以创建LZX文件并进行测试。 **...

    OpenLaszlo-开源

    这使得开发者能够利用OpenLaszlo来创建跨平台、兼容多种浏览器的富互联网应用。该项目的官方站点在http://openlaszlo.org,这是一个宝贵的资源库,包含了文档、示例代码和社区支持,对于学习和使用OpenLaszlo的人来...

    英文原版-Laszlo in Action 1st Edition

    OpenLaszlo is an increasingly popular open-source platform for the development and delivery of rich internet applications across multiple platforms: Flash, DHTML, and J2ME. The dramatic emergence of ...

    geoar:WMSWFS OpenLaszlo 客户端

    Geoar - WMS/WFS OpenLaszlo 客户端GeoAr 是 WMS 和 WFS 服务的富客户端实现。 它是在 LZX (OpenLaszlo) 上开发的,因此它向用户的浏览器提供 dhtml 或 flash,从而提供在它们之间进行选择的机会,但只有一个服务器...

    Openlaslzo+jsf

    ### Openlaszlo+JSF:SWF动画制作与Struts框架整合配置详解 #### 一、OpenLaszlo简介及SWF动画制作 **OpenLaszlo**是一款开源的跨平台开发工具,用于创建RIA(Rich Internet Applications)。它允许开发者使用一种...

    spket1.6.18

    "Spket1.6.18"是一款专为JavaScript和OpenLaszlo开发的智能代码提示工具,它作为Eclipse集成开发环境(IDE)的插件,极大地提升了开发者的工作效率。这款工具的主要功能是为JavaScript和OpenLaszlo语言提供语法高亮...

    改造OpenMeetings成为Flash视频会议室(三)

    在这一部分,我们将深入探讨如何理解和修改OpenMeetings的源代码,特别是针对那些不熟悉OpenLaszlo开发语言的开发者。 OpenLaszlo是一种用于构建富互联网应用程序(RIA)的平台,它允许开发者用一种统一的声明式语言...

    Laszlo与web工程

    - 首先,你需要下载 OpenLaszlo Server 的servlet包,例如 `openlaszlo-3.3.3-servlet.war`,并将它部署到Tomcat的 `webapps` 目录下。 - 启动Tomcat后,会自动解压war文件,并创建一个名为 `openlaszlo-3.3.3-...

    openmeeting安装

    9. **OpenLaszlo Server**: OpenLaszlo用于编译OpenMeeting的客户端界面。下载并安装相应版本的OpenLaszlo服务器,然后进行配置。 10. **OpenMeeting源代码**: 通过Subversion (SVN) 从指定URL获取OpenMeeting的源...

    huoyan.zip_火焰识别c++

    如果这个项目与OpenLaszlo有关,那么可能是将C++编写的火焰识别算法集成到OpenLaszlo应用中,以提供更丰富的视觉体验。 文件列表中的“实例77”可能是一个示例项目或者代码片段,展示了如何使用提供的C++ API来实现...

    Laszlo技术手册

    手册详尽地介绍了Laszlo的核心概念、安装配置、LZX语言、事件处理、动态效果、约束机制以及OpenLaszlo的开发实践,旨在帮助读者快速掌握Laszlo并应用于Web工程。 Laszlo是一种开源的富互联网应用程序(RIA)开发...

Global site tag (gtag.js) - Google Analytics