资讯专栏INFORMATION COLUMN

【easeljs】事件汇总

impig33 / 2953人阅读

摘要:定义于,表示只有这个对象才有这个事件。加入版本,表示从这个版本起才加入这个事件,老版本没有这个事件。这是目前唯一非点击的鼠标输入事件。这事件在拖拽和类似的需求里很有用。这个事件一定要启用。

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

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

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

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

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

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

stage的事件全加进来了

easeljs事件默认是不支持touch设备的,需要这样才可以
var stage = new createjs.Stage("canvasId");
createjs.Touch.enable(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事件都会持续发生在此对象上,直到松开鼠标按钮。这事件在拖拽和类似的需求里很有用。
(如果stage上加了这个事件侦听,当stage上什么元素都没有时,这个是无效的,需要用stagemousemove

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范围内。

tick

继承自 DisplayObject: tick:642
加入版本 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"].

paused Boolean
指出ticker当前是否暂停

delta Number

从上次触发事件以来,经过了多少毫秒。

time Number

Ticker实例化之后经过了多少毫秒

runTime Number

Ticker实例化之后未被暂停的状态下经过了多少毫秒。例如,你可以决定用time-runTime初始化后被暂停的总时间(The total time in ms that Ticker was not paused since it was initialized. For example, you could determine the amount of time that the Ticker has been paused since initialization with time-runTime.)

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.

文章版权归作者所有,未经允许请勿转载,若此文章存在违规行为,您可以联系管理员删除。

转载请注明本文地址:https://www.ucloud.cn/yun/78593.html

相关文章

  • easeljs】矢量形状 Shape类

    摘要:类介绍继承自一个形状允许你在显示列表中显示矢量图。它包含一个带有所有绘制矢量图形的方法的图形实例。实例可以在多个实例之间共享,以做到一样的矢量图形在画布上有多个不同位置和不同变形的复制。 类介绍 继承自 DisplayObject 一个Shape(形状)允许你在显示列表中显示矢量图。它包含一个带有所有绘制矢量图形的方法的Graphics(图形)实例。Graphics实例可以在多个Sha...

    mengbo 评论0 收藏0
  • Vue项目引入CreateJS的方法(亲测)

    摘要:前言介绍是基于开发的一套模块化的库和工具。包含类工具库提供了一套完整的,层次化的显示列表的互动方式来更简单的处理画布。方法一安装注意这里下载的版本不是官网最新版本。 1 前 言 1.1 CreateJS介绍 showImg(https://segmentfault.com/img/remote/1460000019340654); CreateJS是基于HTML5开发的一套模块化的库和...

    golden_hamster 评论0 收藏0
  • CreateJS入门 -- 注释详细到爆炸(My Style)

    摘要:以后所有的文章都会第一时间更新到这里,然后同步到其他平台。获取画布的宽和高,后面计算使用定义静态资源人物动作雪碧图天空地面远山近山创建资源加载队列用还是用标签来加载如果是的时候,就用标签来加载,如果不能用标签的话,就用来加载。 写在前面 首先,还是谢谢大家的支持,谢谢!记得在之前的文章中我说过自己算是一个半文艺程序员,也一直想着写一写技术性和其他偏文学性的文章。虽然自己的底子没有多么优...

    Render 评论0 收藏0

发表评论

0条评论

最新活动
阅读需要支付1元查看
<