当前位置

网站首页> 程序设计 > 开源项目 > 程序开发 > 浏览文章

【easeljs】事件汇总 - 黒之染

作者:小梦 来源: 网络 时间: 2024-02-26 阅读:

文章说明:为了方便我自己查找easeljs的所有事件,所以我从easeljs的文档里抄过来加上自己的翻译,会慢慢补全,漏了的,错了的,评论一下我会补上去哦。(不确定翻译对不对的地方我会留着原文。)

  1. 继承自,表示所有继承自那个对象的对象都有这个事件。

  2. 定义于,表示只有这个对象才有这个事件。

  3. 加入版本,表示从这个版本起才加入这个事件,老版本没有这个事件。

  4. “此对象”表示被添加了这个事件的对象

  5. 与jquery和js一致,事件的回调函数第一个参数会带上事件对象,在easeljs文档event类中可以看到各个事件属性的说明。

  6. stage的事件全加进来了

添加事件的方法

on ( type listener [scope] [once=false] [data] [useCapture=false] ) Function

继承自 EventDispatcher
A shortcut method for using addEventListener that makes it easier to specify an execution scope, have a listener only run once, associate arbitrary data with the listener, and remove the listener.
This method works by creating an anonymous wrapper function and subscribing it with addEventListener. The wrapper function is returned for use with removeEventListener (or off).
IMPORTANT: To remove a listener added with on, you must pass in the returned wrapper function as the listener, or use remove. Likewise, each time you call on a NEW wrapper function is subscribed, so multiple calls to on with the same params will create multiple listeners.
Example

var listener = myBtn.on("click", handleClick, null, false, {count:3});function handleClick(evt, data) {    data.count -= 1;    console.log(this == myBtn); // true - scope defaults to the dispatcher    if (data.count == 0) {        alert("clicked 3 times!");        myBtn.off("click", listener);        // alternately: evt.remove();    }}

Parameters:

type String
The string type of the event.
listener Function | Object
An object with a handleEvent method, or a function that will be called when the event is dispatched.
[scope] Object optional
The scope to execute the listener in. Defaults to the dispatcher/currentTarget for function listeners, and to the listener itself for object listeners (ie. using handleEvent).
[once=false] Boolean optional
If true, the listener will remove itself after the first time it is triggered.
[data] optional
Arbitrary data that will be included as the second parameter when the listener is called.
[useCapture=false] Boolean optional
For events that bubble, indicates whether to listen for the event in the capture or bubbling/target phase.
Returns:

Function: Returns the anonymous function that was created and assigned as the listener. This is needed to remove the listener later using .removeEventListener.

added

继承自 DisplayObject
当此对象被add到其它容器对象时触发

click

继承自 DisplayObject
加入版本 0.6.0
在用户按下左键并在此对象上松开左键后触发。

dblclick

继承自 DisplayObject
加入版本 0.6.0
当用户在此对象上双击左键后触发。

drawend

定义于 stage
加入版本 0.7.0
每次显示列表被绘制到canvas后并且restore过canvas context后触发。
Dispatched each update immediately after the display list is drawn to the canvas and the canvas context is restored.

drawstart

定义于 stage
加入版本 0.7.0
在清除画布和绘制显示列表之前触发。可以在调用event对象上使用preventDefault取消这次绘制。
Dispatched each update immediately before the canvas is cleared and the display list is drawn to it. You can call preventDefault on the event object to cancel the draw.

mousedown

继承自 DisplayObject
加入版本 0.6.0
用户在此对象上按下左键后触发。

mouseenter

定义于 stage
加入版本 0.7.0
当鼠标指针从canvas区域外(mouseInBounds == true)移进canvas区域(mouseInBounds == false)后触发。这是目前唯一非点击的鼠标输入事件。

mouseleave

定义于 stage
加入版本 0.7.0
当鼠标从canvas区域内(mouseInBounds == true)移出(mouseInBounds == false)后触发。这是目前唯一非点击的鼠标输入事件。(我也不知道为何这里的mouseInBounds和上面的相反,看原文吧)

mouseout

继承自 DisplayObject
加入版本 0.6.0
当用户鼠标从该对象的任意一个子项离开后触发。这个事件一定要启用enableMouseOver。另请参阅rollout。(写好rollout后如果我还记得这里,会把这个链接弄好)

mouseover

继承自 DisplayObject
加入版本 0.6.0
当用户鼠标进入该对象的任意一个子项后触发。这个事件一定要启用enableMouseOver。另请参阅rollout。(写好rollout后如果我还记得这里,会把这个链接弄好)

pressmove

继承自 DisplayObject
加入版本 0.7.0
在此对象上发生了mousedown事件后,无论鼠标是否移动,pressmove事件都会持续发生在此对象上,直到松开鼠标按钮。这事件在拖拽和类似的需求里很有用。

pressup

继承自 DisplayObject
加入版本 0.7.0
在此对象上发生了mousedown事件后,松开鼠标会触发。这事件在拖拽和类似的需求里很有用。

removed

继承自 DisplayObject
当此对象从它的父对象上移除后会触发。

rollout

继承自 DisplayObject
加入版本 0.7.0
这个事件和mouseout很像,但有这些不同:它不冒泡,而且它把该对象的内容认为是一个整体。
例如,myContainer包含着两个有重叠部分的子项:shapeAshapeB。用户移动他的鼠标到shapeA上,然后直接移到shapeB上,然后离开他们俩。如果myContainerMouseout:event,会收到两个事件,每个事件指向一个子元素:

  • 当鼠标离开shapeAtarget=shapeA

  • 当鼠标离开shapeBtarget=shapeB

然而当事件换成rollout,只会在离开myContainer时才会触发事件(不仅仅是离开shapeB),target=myContainer。这个事件一定要启用enableMouseOver
(jquery也有这样的,但是我忘记jquery中哪个是只离开父对象才触发了。)

rollover

继承自 DisplayObject
加入版本 0.7.0
这个事件和mouseover很像,不同之处跟rolloutmouseout的不同之处是一样的。这个事件一定要启用enableMouseOver

stagemousedown

定义于 stage
加入版本 0.6.0
用户在canvas上按下左键后触发。

stagemousemove

定义于 stage
加入版本 0.6.0
当用户在canvas上移动鼠标时持续触发。

stagemouseup

定义于 stage
加入版本 0.6.0
当用户在stage的某处按下左键,然后在页面中能接收事件的任意一处(不同浏览器有些不同)松开左键。可以使用mouseInBounds检查鼠标是否在stage范围内。

经pc chrome测试,stagemousedown、stagemousemove、stagemouseup这三个事件都是在点击并松开后触发,触发顺序是stagemousemove>stagemousedown>stagemouseup,只要鼠标移动过了,这3个就不会触发了

tick

Inherited from DisplayObject: tick:642
Available since 0.6.0
Dispatched on each display object on a stage whenever the stage updates. This occurs immediately before the rendering (draw) pass. When update is called, first all display objects on the stage dispatch the tick event, then all of the display objects are drawn to stage. Children will have their Tick:event event dispatched in order of their depth prior to the event being dispatched on their parent.
Event Payload:

target Object
The object that dispatched the event.
type String
The event type.
params Array
An array containing any arguments that were passed to the Stage.update() method. For example if you called stage.update("hello"), then the params would be ["hello"].

tickend

Defined in tickend:294
Available since 0.7.0
Dispatched each update immediately after the tick event is propagated through the display list. Does not fire if tickOnUpdate is false. Precedes the "drawstart" event.

tickstart

Defined in tickstart:287
Available since 0.7.0
Dispatched each update immediately before the tick event is propagated through the display list. You can call preventDefault on the event object to cancel propagating the tick event.

网友最爱