`

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

    OpenLaszlo is the leading open source platform for the development and delivery of rich Internet applications on the World Wide Web.

    openlaszlo本地帮助文档

    英文版的openlaszlo的使用手册,html格式的。 哪位如果能做成chm或者pdf的就更好了。 openlaszlo是RIA的一种实现,个人感觉比Flex要灵活的多。

    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....

    Applet & Openlaszlo

    Applet与Openlaszlo的通信。 采用此方式可以做相关的软件在线安装,上传,下载的FLASH效果。

    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 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,从而提供在它们之间进行选择的机会,但只有一个服务器...

    OpenLaszlo-开源

    OpenLaszlo是一个开放源代码平台,用于创建单页应用程序,这些应用程序可以编译为Flash或HTML5进行Web部署。 该项目的站点位于http://openlaszlo.org。

    Laszlo技术手册续

    这是Laszlo与web的PPT! 希望对希望让laszlo与web结合的朋友有所帮助!

    spket1.6.18

    js openlaszlo智能提示,很好用的工具,这是eclipse的插件

    openMeetings二次开发高手的七篇文章

    PhMeetings是基于开源WEB视频会议系统OpenMeetings开发的一个实验性...由于资料的缺乏以及对OpenLaszlo编程的陌生,其中艰辛不足为外人道。今日发一声感慨:如果你想折磨一个程序员,那就让他去干开源软件的二次开发!

    huoyan.zip_火焰识别c++

    api c++ 火焰效果 绚丽的效果,而openlaszlo最终也是编译成swf来运行

    FlashBuilder_4_LS10.part01.rar

    FlashBuilder开发工具,是开发java网页及OpenLaszlo,Laszlo富客户端必备工具。本人安装在电脑运行正常。

    FlashBuilder_4_LS10.part02.rar

    FlashBuilder开发工具,是开发java网页及OpenLaszlo,Laszlo富客户端必备工具。本人安装在电脑运行正常。

    FlashBuilder_4_LS10.part03.rar

    FlashBuilder开发工具,是开发java网页及OpenLaszlo,Laszlo富客户端必备工具。本人安装在电脑运行正常。

    FlashBuilder_4_LS10.part04.rar

    FlashBuilder开发工具,是开发java网页及OpenLaszlo,Laszlo富客户端必备工具。本人安装在电脑运行正常。

Global site tag (gtag.js) - Google Analytics