Manually dispatching events手动触发事件

You can manually dispatch events using a component instances  dispatchEvent() method. All components that extend UIComponent have this method. The method is inherited from the EventDispatcher class, which UICom-ponent extends.

The syntax for the dispatchEvent() method is as follows:

你可以使用组件的实例方法dispatchEvent() 来手动派发事件。所有的继承UIComponent的组件都有此方法,该方法继承自EventDispatcher类。

 dispatchEvent() 语法如下:
objectInstance.dispatchEvent(event:Event):Boolean
When dispatching an event, you must create a new Event object. The syntax for the Event object constructor is as
follows:

当你派发一个事件时,你必须创建一个Event对象,Event的构造函数如下:
Event(event_type:String, bubbles:Boolean, cancelable:Boolean)
The event_type parameter is the type property of the Event object. The bubbles and cancelable parameters
are optional and both default to false.

event_type参数是事件类型。bubbles and cancelable参数是可选的,默认都是false。
You can use the dispatchEvent() method to dispatch any event you want, not just a custom event. You can dispatch a Button controls click event, even though the user did not click a Button control, as in the following example:

你可以使用 dispatchEvent() 来派发你想派发的任何事件,不局限于自定义的事件。你可以派发一个Button控件的click事件,即使用户并没有单击Button控件,如下例子:



You can also manually dispatch an event in an MXML tag. In the following example, moving the mouse pointer
over the button triggers the buttons click event:

你也可以在MXML标签中手动派发事件。在下面的例子中,当鼠标划过button按钮将会触发button的click事件。

Your Flex application is not required to handle the newly dispatched event. If you trigger an event that has no listeners, Flex ignores the event.

Flex应用不一定必须处理新派发的事件,如果你触发一个事件而这个事件没有监听者,那么Flex将会忽略它。
You can set properties of the Event object in ActionScript, but you cannot add new properties because the object is not dynamic. The following example intercepts a click event. It then creates a new MouseEvent object and dispatches it as a doubleClick event. In addition, it sets the value of the shiftKey property of the MouseEvent object to true, to simulate a Shift-click on the keyboard.

你可以在Actionscript中设置Event对象的属性值,但是你不能给它添加新的属性因为该对象不是动态的。下面的例子拦截了一个click事件,

然后创建了一个新的MouseEvent对象把它作为doubleClick事件派发。此外,它还把MouseEvent的shiftKey属性设置为true来模拟键盘上的Shift-click。

If you want to add custom properties to an Event object, you must extend the Event object and define the new properties in your own custom class. You can then manually dispatch your custom events with the dispatchEvent() method, as you would any event.
If you create a custom ActionScript class that dispatches its own events but does not extend UIComponent, you can extend the flash.events.EventDispatcher class to get access to the addEventListener(), removeEventListener(), and dispatchEvent() methods.

如果你想为一个Event对象添加上自定义属性,就必须得继承Event类,在你的定义的新类中定义新的属性。然后你可以用dispatchEvent()方法手动派发你的自定义事件。

如果你想创建一个自定义的AS类来派发它自己的事件,而该类并没有继承UIComponent你可以继承flash.events.EventDispatcher 类来使用 addEventListener(),
removeEventListener(), and dispatchEvent() methods.方法。
For more information on creating custom classes, see Creating and Extending Adobe Flex 3 Components.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值