【easeljs】事宜汇总

文章申明:为了轻易我本身查找easeljs的一切事宜,所以我从easeljs的文档里抄过来加上本身的翻译,会逐步补全,漏了的,错了的,批评一下我会补上去哦。(不确定翻译对不对的处所我会留着原文。)

  1. 继续自,示意一切继续自谁人对象的对象都有这个事宜。
  2. 定义于,示意只要这个对象才有这个事宜。
  3. 到场版本,示意从这个版本起才到场这个事宜,老版本没有这个事宜。
  4. “此对象”示意被增加了这个事宜的对象
  5. 与jquery和js一致,事宜的回调函数第一个参数会带上事宜对象,在easeljs文档event类中能够看到各个事宜属性的申明。
  6. 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://segmentfault.com/a/1190000004374399
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞